コード例 #1
0
 public IHttpActionResult PostEmployeeCar(EmployeeCarDTO employeeCar)
 {
     if (employeeCar == null || !ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         EmployeeCar car        = employeeCar.FromDTO();
         UnitOfWork  unitOfWork = new UnitOfWork(factory);
         employeeCar.Id = car.NewId(unitOfWork);
         unitOfWork.EmployeeCarsRepository.Insert(car);
         unitOfWork.Save();
         //cos there are no included object-properies we need to load, then just ToDTO call
         EmployeeCarDTO dto = car.ToDTO();
         return(CreatedAtRoute("GetEmployeeCar", 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 PutEmployeeCar(int id, EmployeeCarDTO employeeCar)
        {
            if (employeeCar == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != employeeCar.Id)
            {
                return(BadRequest());
            }
            try
            {
                EmployeeCar car = employeeCar.FromDTO();

                UnitOfWork unitOfWork = new UnitOfWork(factory);
                unitOfWork.EmployeeCarsRepository.Update(car);
                unitOfWork.Save();


                //cos there are no included object-properies we need to load, then just ToDTO call
                EmployeeCarDTO dto = car.ToDTO();
                return(Ok(dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }