public IHttpActionResult updateTask(int taskId, TaskDTO taskToCreate) { using (IUnitOfWork dbTask = new UnitOfWork()) { DboTasks task = dbTask.DataRepo.GetTask(taskId); if (task == null) { List <Problem> errors = new List <Problem> { new Problem() { Field = "TaskId", Message = "Invalid Task Id" } }; var response = Request.CreateResponse(HttpStatusCode.BadRequest, errors); return(ResponseMessage(response)); } DboTasks updateTask = taskToCreate.ToDboTask(); updateTask.taskId = taskId; List <DboUsers> users = dbTask.DataRepo.GetAllUsers(); List <DboUsers> assignedUsers = taskToCreate.AssignedUsersId != null? users.Where(u => taskToCreate.AssignedUsersId.Contains(u.userId)).ToList() : null; updateTask = dbTask.DataRepo.UpdateTask(updateTask, assignedUsers); List <Problem> validatrionErrors = new List <Problem>(); if (!updateTask.Validate(validatrionErrors)) { var response = Request.CreateResponse(HttpStatusCode.BadRequest, validatrionErrors); return(ResponseMessage(response)); } dbTask.SaveChanges(); return(Ok(updateTask.ToTaskDTO())); } }
public IHttpActionResult CreatTask(TaskDTO taskToCreate) { using (IUnitOfWork dbTask = new UnitOfWork()) { DboTasks newTask = taskToCreate.ToDboTask(); List <DboUsers> users = dbTask.DataRepo.GetAllUsers(); List <DboUsers> assignedUsers = taskToCreate.AssignedUsersId != null? users.Where(u => taskToCreate.AssignedUsersId.Contains(u.userId)).ToList() : null; newTask = dbTask.DataRepo.CreateNewTask(newTask, assignedUsers); List <Problem> errors = new List <Problem>(); if (!newTask.Validate(errors)) { var response = Request.CreateResponse(HttpStatusCode.BadRequest, errors); return(ResponseMessage(response)); } dbTask.SaveChanges(); return(Ok(newTask.ToTaskDTO())); } }