using System.ComponentModel.DataAnnotations; 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([Required]TId id) { return Handle(Busines.GetSingleById(id)); } [HttpGet] [Route("[controller]")] public LuApiWrapperDbo> GetMultiple([Required]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][Required]TDboCreate data) { return Handle(Busines.AddDbo(data)); } [HttpPost] [Route("[controller]/{id}")] public LuApiWrapperDbo EditSingleByIdDbo([Required]TId id, [FromBody][Required]TDboUpdate data) { return Handle(Busines.EditSingleByIdDbo(id, data)); } [HttpDelete] [Route("[controller]/{id}")] public LuApiWrapperDbo Delete([Required]TId id) { return Handle(Busines.DeleteSingleByIdDbo(id)); } } }