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)); } }
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)); } }