Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
 internal static BusinessSector Hydrate(BusinessSectorDTO dto)
 {
     return(new BusinessSector()
     {
         ID = dto.Id,
         Code = dto.Code,
         Name = dto.Name
     });
 }
Esempio n. 3
0
        public BusinessSectorDTO RemoveSector(int id)
        {
            BusinessSectorDTO deletedSector = GetSector(id);

            if (deletedSector != null)
            {
                sectorRepository.Remove(id);
            }
            return(deletedSector);
        }
Esempio n. 4
0
        public ActionResult <BusinessSectorDTO> Delete(int id)
        {
            BusinessSectorDTO deletedSector = sectorService.RemoveSector(id);

            if (deletedSector == null)
            {
                return(NotFound());
            }
            return(Ok(deletedSector));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        public ActionResult <BusinessSectorDTO> GetById(int id)
        {
            BusinessSectorDTO sector = sectorService.GetSector(id);

            if (sector == null)
            {
                return(NotFound());
            }
            return(sector);
        }
Esempio n. 7
0
        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));
        }