public IHttpActionResult CreateTask(TaskDto taskDto) { Completed completed = new Completed(); To_Do to_Do = new To_Do(); var userID = User.Identity.GetUserId(); Milestone task = new Milestone(); using (var dc = new ProgressTrackerEntities()) { var newTask = (Milestone)taskDto; newTask.SortOrder = dc.Milestones.Max(t => t.SortOrder) + 1; newTask.StudentNumber = userID; if (newTask.Progress == 1) { newTask.Status = "Completed"; newTask.Completed = true; completed.Progress = newTask.Progress; completed.StudentNumber = newTask.StudentNumber; dc.Completeds.Add(completed); dc.SaveChanges(); } if (newTask.Progress > 0 && newTask.Progress < 1) { newTask.Status = "In-Progress"; newTask.InProgress = true; } if (newTask.Progress == 0) { newTask.Status = "To-Do"; newTask.ToDo = true; to_Do.StudentNumber = newTask.StudentNumber; to_Do.Progress = newTask.Progress; dc.To_Do.Add(to_Do); dc.SaveChanges(); } dc.Milestones.Add(newTask); dc.SaveChanges(); return(Ok(new { tid = newTask.Id, action = "inserted" })); } }
public IHttpActionResult EditTask(int id, TaskDto taskDto) { var userID = User.Identity.GetUserId(); Completed completed = new Completed(); To_Do to_Do = new To_Do(); using (var dc = new ProgressTrackerEntities()) { var updatedTask = (Milestone)taskDto; updatedTask.Id = id; if (taskDto.progress == 1) { updatedTask.Status = "Completed"; completed.Progress = updatedTask.Progress; completed.StudentNumber = updatedTask.StudentNumber; dc.Completeds.Add(completed); dc.SaveChanges(); } else if (taskDto.progress == 0) { updatedTask.Status = "To-Do"; to_Do.StudentNumber = updatedTask.StudentNumber; to_Do.Progress = updatedTask.Progress; dc.To_Do.Add(to_Do); dc.SaveChanges(); } else { updatedTask.Status = "In-Progress"; } dc.Entry(updatedTask).State = EntityState.Modified; dc.SaveChanges(); return(Ok(new { action = "updated" })); } }