public BusinessSectorDTO SaveSector(BusinessSectorDTO sector) { if (sector == null) { return(null); } BusinessSector savedSector = null; if (sector.Id.HasValue) { savedSector = sectorRepository.Update(BusinessSector.Hydrate(sector)); } else { savedSector = sectorRepository.Insert(BusinessSector.Hydrate(sector)); } if (savedSector != null) { return(savedSector.getDTO()); } else { return(null); } }
internal static BusinessSector Hydrate(BusinessSectorDTO dto) { return(new BusinessSector() { ID = dto.Id, Code = dto.Code, Name = dto.Name }); }
public BusinessSectorDTO RemoveSector(int id) { BusinessSectorDTO deletedSector = GetSector(id); if (deletedSector != null) { sectorRepository.Remove(id); } return(deletedSector); }
public ActionResult <BusinessSectorDTO> Delete(int id) { BusinessSectorDTO deletedSector = sectorService.RemoveSector(id); if (deletedSector == null) { return(NotFound()); } return(Ok(deletedSector)); }
public ActionResult <BusinessSectorDTO> Create(BusinessSectorDTO sector) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BusinessSectorDTO newSector = sectorService.SaveSector(sector); return(CreatedAtRoute(routeName: "GetBusinessSector", routeValues: new { id = newSector.Id }, value: newSector)); }
public ActionResult <BusinessSectorDTO> GetById(int id) { BusinessSectorDTO sector = sectorService.GetSector(id); if (sector == null) { return(NotFound()); } return(sector); }
public ActionResult <BusinessSectorDTO> Update(int id, BusinessSectorDTO sector) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BusinessSectorDTO updatedSector = sectorService.SaveSector(sector); if (updatedSector == null) { return(NotFound()); } return(Ok(updatedSector)); }