2020-03-22 14:47:59 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-04-19 18:22:44 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-03-25 23:24:58 +01:00
|
|
|
using zero.Core;
|
2020-04-16 00:56:22 +02:00
|
|
|
using zero.Core.Identity;
|
2020-04-19 18:22:44 +02:00
|
|
|
using zero.Web.Mapper;
|
2020-03-22 14:47:59 +01:00
|
|
|
|
2020-03-24 23:09:29 +01:00
|
|
|
namespace zero.Web.Controllers
|
2020-03-22 14:47:59 +01:00
|
|
|
{
|
2020-04-15 14:09:52 +02:00
|
|
|
[ZeroAuthorize]
|
2020-03-22 14:47:59 +01:00
|
|
|
public abstract class BackofficeController : Controller
|
|
|
|
|
{
|
2020-03-25 23:24:58 +01:00
|
|
|
protected IZeroConfiguration Configuration { get; set; }
|
|
|
|
|
|
2020-04-19 18:22:44 +02:00
|
|
|
protected IMapper Mapper { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BackofficeController(IZeroConfiguration config, IMapper mapper)
|
|
|
|
|
{
|
|
|
|
|
Configuration = config;
|
|
|
|
|
Mapper = mapper;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 23:24:58 +01:00
|
|
|
|
|
|
|
|
public BackofficeController(IZeroConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
Configuration = config;
|
|
|
|
|
}
|
2020-04-19 18:22:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
protected IActionResult Json<T, TTarget>(T model) where TTarget : class, new()
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return new StatusCodeResult(404);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-21 16:23:43 +02:00
|
|
|
if (Mapper == null)
|
|
|
|
|
{
|
|
|
|
|
// TODO show error with help on how to inject mapper in constructor + base constructor
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 18:22:44 +02:00
|
|
|
return Json(Mapper.Map<T, TTarget>(model));
|
|
|
|
|
}
|
2020-03-22 14:47:59 +01:00
|
|
|
}
|
|
|
|
|
}
|