1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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;
-
- 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)
- {
- 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));
- }
- }
- }
|