|
|
|
@ -12,6 +12,9 @@ using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure.Web.Mvc
|
|
|
|
|
{
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("Admin/[controller]/[action]")]
|
|
|
|
|
public class CrudController<TEntity, TSearchModel, TDisplayModel, TEditModel> : BaseController
|
|
|
|
|
where TEntity : BaseEntity
|
|
|
|
|
where TSearchModel : PagedListModel<TDisplayModel>
|
|
|
|
@ -23,6 +26,7 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
this._repo = repo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public virtual IActionResult Index(TSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
@ -50,9 +54,10 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
.ToList());
|
|
|
|
|
ViewData["EntityTypeExt"] = typeof(TEntity);
|
|
|
|
|
ViewData["ModelTypeExt"] = typeof(TDisplayModel);
|
|
|
|
|
return View(model);
|
|
|
|
|
return this.Result(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public virtual IActionResult Details(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var query = this._repo.ReadOnlyTable();
|
|
|
|
@ -60,9 +65,10 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
var entity = query.FirstOrDefault(o => o.Id == id);
|
|
|
|
|
var model = entity.To<TDisplayModel>();
|
|
|
|
|
this.ToDisplayModel(entity, model);
|
|
|
|
|
return View(model);
|
|
|
|
|
return Result(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public virtual IActionResult Add()
|
|
|
|
|
{
|
|
|
|
|
var model = Activator.CreateInstance<TEditModel>();
|
|
|
|
@ -97,6 +103,7 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public virtual IActionResult Edit(Guid id)
|
|
|
|
|
{
|
|
|
|
|
var query = this._repo.ReadOnlyTable();
|
|
|
|
@ -137,6 +144,7 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public virtual IActionResult Remove(List<Guid> list)
|
|
|
|
|
{
|
|
|
|
|
if (list == null)
|
|
|
|
@ -161,6 +169,7 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Restore(List<Guid> list)
|
|
|
|
|
{
|
|
|
|
|
if (list == null)
|
|
|
|
@ -185,6 +194,7 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public virtual IActionResult Delete(List<Guid> list)
|
|
|
|
|
{
|
|
|
|
|
if (list == null)
|
|
|
|
@ -212,44 +222,54 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual IQueryable<TEntity> Include(IQueryable<TEntity> query)
|
|
|
|
|
{
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual IQueryable<TEntity> Query(TSearchModel model, IQueryable<TEntity> query)
|
|
|
|
|
{
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void ToEditModel(TEntity entity, TEditModel model)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void ToDisplayModel(TEntity entity, TDisplayModel model)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void ToEntity(TEditModel model, TEntity entity)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void OnEdit(TEntity entity, TEditModel model)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void OnInserted(TEntity entity)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void OnUpdated(TEntity entity)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public virtual void OnDeleted(TEntity entity)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
public override void OnActionExecuting(ActionExecutingContext context)
|
|
|
|
|
{
|
|
|
|
|
if (context == null)
|
|
|
|
@ -291,5 +311,11 @@ namespace Infrastructure.Web.Mvc
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
private IActionResult Result(object model)
|
|
|
|
|
{
|
|
|
|
|
return this.Request.Headers["accept"].ToString().Contains("json") ? Json(model) as IActionResult : View(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|