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