public async Task <IActionResult> GetById(int id) { Model.Zoning entity = await dataAccess.FindByIdAsync(id); if (entity == null) { return(NotFound()); } DTO.Zoning zoning = Mapper.Map <DTO.Zoning>(entity); zoning.NbImplantations = new CompanyDataAccess(Context).GetTotalCount(zoningId: zoning.Id); return(Ok(zoning)); }
public async Task <IActionResult> Post([FromBody] DTO.Zoning data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Model.Zoning entity = Mapper.Map <Model.Zoning>(data); entity = await dataAccess.AddAsync(entity); DTO.Zoning zoning = Mapper.Map <DTO.Zoning>(entity); zoning.NbImplantations = new CompanyDataAccess(Context).GetTotalCount(zoningId: zoning.Id); return(Created($"api/Zoning/{entity.Id}", zoning)); }
public async Task <IActionResult> Put(int id, [FromBody] DTO.Zoning data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Model.Zoning entity = await dataAccess.FindByIdAsync(id); if (entity == null) { return(NotFound()); } entity = await dataAccess.EditAsync(Mapper.Map(data, entity)); DTO.Zoning zoning = Mapper.Map <DTO.Zoning>(entity); zoning.NbImplantations = new CompanyDataAccess(Context).GetTotalCount(zoningId: zoning.Id); return(Accepted(zoning)); }