public IActionResult DeleteTask(TaskModel task) { using (TeamsDbEntities entities = new TeamsDbEntities()) { Data.Task taskEntity = entities.Tasks.FirstOrDefault(x => x.ID == task.ID && task.TeamID == x.TeamID); taskEntity.IsDelete = true; entities.SaveChanges(); return(Ok(new ResponseBase { Result = "Success" })); } }
public IActionResult SaveTask(TaskModel task) { DateTime today = DateTime.Now; using (TeamsDbEntities entities = new TeamsDbEntities()) { Data.Task taskEntity = entities.Tasks.FirstOrDefault(x => x.ID == task.ID); Data.Task taskResponse = new Data.Task(); if (taskEntity == default) { taskEntity = new Data.Task { Header = task.Header, Detail = task.Detail, UserID = task.UserID, Progress = (short)task.Progress, CreateBy = task.CreateBy, CreateDate = today, IsDelete = false, StartDate = task.StartDate, EndDate = task.EndDate, TeamID = task.TeamID }; taskResponse = entities.Tasks.Add(taskEntity); } else { taskEntity.Header = task.Header; taskEntity.Detail = task.Detail; taskEntity.StartDate = task.StartDate; taskEntity.EndDate = task.EndDate; taskEntity.UserID = task.UserID; taskEntity.Progress = (short)task.Progress; } Data.TaskLog taskLog = new TaskLog { TaskID = taskEntity == default ? taskResponse.ID : taskEntity.ID, ProgressID = (short)task.Progress, UserID = task.UserID, ModifyBy = task.CreateBy, ModifyDate = DateTime.Now, }; entities.TaskLogs.Add(taskLog); entities.SaveChanges(); return(Ok(new ResponseBase { Result = "Success" })); } }