using System; using System.Linq; using Luticate2.Utils.Dbo; using Luticate2.Utils.Dbo.Basic; using Luticate2.Utils.Dbo.Filter; using Luticate2.Utils.Dbo.OrderBy; using Luticate2.Utils.Interfaces; using Microsoft.AspNetCore.Mvc; namespace Luticate2.Utils.Controllers { public abstract class LuCrudController : LuController where TDboCreate : class where TDboRead : class where TDboUpdate : class where TBusiness : ILuCrudInterface { protected readonly TBusiness Busines; protected LuCrudController(TBusiness busines) { Busines = busines; } [HttpGet] [Route("[controller]/{id}")] public LuApiWrapperDbo GetSingleById(TId id) { return Handle(Busines.GetSingleById(id)); } [HttpGet] [Route("[controller]")] public LuApiWrapperDbo> GetMultiple(LuOrderByDbo orderBy, LuFilterDbo filter, int page = 0, int perPage = int.MaxValue) { return Handle(Busines.GetMultiple(orderBy, filter, page, perPage)); } [HttpPost] [Route("[controller]")] public LuApiWrapperDbo AddDbo([FromBody]TDboCreate data) { return Handle(Busines.AddDbo(data)); } [HttpPost] [Route("[controller]/{id}")] public LuApiWrapperDbo EditSingleByIdDbo(TId id, [FromBody]TDboUpdate data) { return Handle(Busines.EditSingleByIdDbo(id, data)); } [HttpDelete] [Route("[controller]/{id}")] public LuApiWrapperDbo Delete(TId id) { return Handle(Busines.DeleteSingleByIdDbo(id)); } } }