public IActionResult Delete(int id) { HelpDesk.Models.Task task = db.Tasks.FirstOrDefault(x => x.ID == id); if (task != null) { db.Tasks.Remove(task); db.SaveChanges(); } return(Ok(task)); }
public IActionResult Post([FromBody] TaskDto task) { if (ModelState.IsValid) { int projectId = task.CurrentProjectId; var userId = task.User; User user = db.Users.Where(u => u.ID == Convert.ToInt32(userId)).FirstOrDefault(); Project project = db.Projects.Where(project1 => projectId == project1.ID).Single(); var taskModel = new HelpDesk.Models.Task() { Title = task.Title, User = user, State = task.State, Description = task.Description, Effort = task.Effort, Progress = task.Progress, StartDate = task.StartDate, EndDate = task.EndDate, CurrentProjectId = project.ID, CurrentProject = project }; //task.CurrentProject = project; db.Tasks.Add(taskModel); db.SaveChanges(); task.ID = taskModel.ID; return(Ok(task)); } return(BadRequest(ModelState)); }