public IActionResult Delete(Task task) { using (var db = new TeisterMaksDbContext()) { db.Tasks.Remove(task); db.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult Edit(Task task) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } using (var db = new TeisterMaksDbContext()) { var taskToEdit = db.Tasks.FirstOrDefault(t => t.Id == task.Id); taskToEdit.Title = task.Title; taskToEdit.Status = task.Status; db.SaveChanges(); return(RedirectToAction("Index")); } }
public IActionResult Create(string title, string status) { if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(status)) { return(RedirectToAction("Index")); } Task task = new Task { Title = title, Status = status }; using (var db = new TeisterMaksDbContext()) { db.Tasks.Add(task); db.SaveChanges(); } return(RedirectToAction("Index")); }