123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.ComponentModel.DataAnnotations;
- using Luticate2.Utils.Dbo.Basic;
- using Luticate2.Utils.Dbo.Filter;
- using Luticate2.Utils.Dbo.OrderBy;
- using Luticate2.Utils.Dbo.PaginatedRequest;
- using Luticate2.Utils.Interfaces;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Options;
-
- namespace Luticate2.Utils.Controllers
- {
- public abstract class LuCrudController<TBusiness, TDboCreate, TDboRead, TDboUpdate, TId> : LuController
- where TDboCreate : class
- where TDboRead : class
- where TDboUpdate : class
- where TBusiness : ILuCrudInterface<TDboCreate, TDboRead, TDboUpdate, TId>
- {
- protected readonly TBusiness Busines;
-
- protected LuCrudController(TBusiness busines, IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo) : base(luUtilsOptionsDbo)
- {
- Busines = busines;
- }
-
- [HttpGet]
- [Route("[controller]/{id}")]
- public virtual LuApiWrapperDbo<TDboRead> GetSingleById([Required]TId id)
- {
- return Handle(Busines.GetSingleById(id));
- }
-
- [HttpGet]
- [Route("[controller]")]
- public virtual LuApiWrapperDbo<LuPaginatedDbo<TDboRead>> GetMultiple([Required]LuPaginatedRequestDbo request)
- {
- return Handle(Busines.GetMultiple(request.OrderBy, request.Filter, request.Page, request.PerPage));
- }
-
- [HttpPost]
- [Route("[controller]")]
- public virtual LuApiWrapperDbo<TDboRead> AddDbo([FromBody][Required]TDboCreate data)
- {
- return Handle(Busines.AddDbo(data));
- }
-
- [HttpPost]
- [Route("[controller]/{id}")]
- public virtual LuApiWrapperDbo<TDboRead> EditSingleByIdDbo([Required]TId id, [FromBody][Required]TDboUpdate data)
- {
- return Handle(Busines.EditSingleByIdDbo(id, data));
- }
-
- [HttpDelete]
- [Route("[controller]/{id}")]
- public virtual LuApiWrapperDbo<TDboRead> Delete([Required]TId id)
- {
- return Handle(Busines.DeleteSingleByIdDbo(id));
- }
- }
- }
|