Example #1
0
 public IHttpActionResult PostTask(TaskDTO taskDTO)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         Task       task       = taskDTO.FromDTO();
         UnitOfWork unitOfWork = new UnitOfWork(factory);
         task.Id = Guid.NewGuid();
         unitOfWork.TasksRepository.Insert(task);
         unitOfWork.Save();
         TaskDTO dto = unitOfWork.TasksRepository
                       .Get(d => d.Id == task.Id, includeProperties: "Creator,Creator.EmployeePassports,Doer,Doer.EmployeePassports")
                       .FirstOrDefault()
                       .ToDTO();
         return(CreatedAtRoute("GetTaskById", new { id = dto.Id }, dto));
     }
     catch (NotFoundException nfe)
     {
         return(NotFound());
     }
     catch (ConflictException ce)
     {
         return(Conflict());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #2
0
        public IHttpActionResult PutTask(Guid id, TaskDTO taskDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != taskDTO.Id)
            {
                return(BadRequest());
            }

            try
            {
                Task       task       = taskDTO.FromDTO();
                UnitOfWork unitOfWork = new UnitOfWork(factory);
                unitOfWork.TasksRepository.Update(task);
                unitOfWork.Save();
                TaskDTO dto = unitOfWork.TasksRepository
                              .Get(d => d.Id == task.Id, includeProperties: "Creator,Creator.EmployeePassports,Doer,Doer.EmployeePassports")
                              .FirstOrDefault()
                              .ToDTO();
                return(Ok(dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }