Пример #1
0
 public IHttpActionResult PostEmployeeGun(EmployeeGunDTO employeeGun)
 {
     if (employeeGun == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         EmployeeGun gun        = employeeGun.FromDTO();
         UnitOfWork  unitOfWork = new UnitOfWork(factory);
         gun.Id = gun.NewId(unitOfWork);
         unitOfWork.EmployeeGunsRepository.Insert(gun);
         unitOfWork.Save();
         EmployeeGunDTO dto = gun.ToDTO();
         return(CreatedAtRoute("GetEmployeeGun", new { id = dto.Id }, dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #2
0
 public IHttpActionResult PutEmployeeGun(int id, EmployeeGunDTO employeeGun)
 {
     if (employeeGun == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != employeeGun.Id)
     {
         return(BadRequest());
     }
     try
     {
         EmployeeGun gun        = employeeGun.FromDTO();
         UnitOfWork  unitOfWork = new UnitOfWork(factory);
         unitOfWork.EmployeeGunsRepository.Update(gun);
         unitOfWork.Save();
         EmployeeGunDTO dto = gun.ToDTO();
         return(Ok(dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }