Example #1
0
        public IActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            using (var db = new TaskDbContext())
            {
                var task = db.Tasks.Find(id);

                if (task == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                db.Tasks.Remove(task);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Home"));
        }