public IHttpActionResult PutTask(int id, TaskDTO taskDTO) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != taskDTO.TodoId) { return BadRequest(); } try { taskRepo.EditTask(taskDTO); } catch (DbUpdateConcurrencyException) { if (taskRepo.GetTaskID(id) == null) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void Create(TaskDTO taskDTO) { User user = db.Users.Find(taskDTO.User.UserId); Task task = mapper.taskDTOToTask(taskDTO); task.User = user; db.Tasks.Add(task); db.SaveChanges(); }
public void EditTask(TaskDTO taskDTO) { User user = db.Users.Find(taskDTO.User.UserId); Task task = mapper.taskDTOToTask(taskDTO); task.User = user; task.UserId = user.UserId; db.Entry(task).State = EntityState.Modified; db.SaveChanges(); }
public IHttpActionResult PostTask(TaskDTO taskDTO) { if (!ModelState.IsValid) { return BadRequest(ModelState); } taskRepo.Create(taskDTO); return CreatedAtRoute("DefaultApi", new { id = taskDTO.TodoId }, taskDTO); }
public Task taskDTOToTask(TaskDTO taskDTO) { return Mapper.Map<Task>(taskDTO); }