Example #1
0
 public IHttpActionResult PostProfession(ProfessionDTO profession)
 {
     if (profession == null)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         Profession prof       = profession.FromDTO();
         UnitOfWork unitOfWork = new UnitOfWork(factory);
         prof.Id = prof.NewId(unitOfWork);
         unitOfWork.ProfessionsRepository.Insert(prof);
         unitOfWork.Save();
         ProfessionDTO dto = unitOfWork.ProfessionsRepository
                             .Get(d => d.Id == prof.Id, includeProperties: "Country")
                             .FirstOrDefault().ToDTO();
         return(CreatedAtRoute("GetProfession", new { id = dto.Id }, dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }