public ActionResult AddTodo(ToDo toDo)
        {
            if (!ModelState.IsValid)
                return RedirectToAction("Listing", "Listing", Data);

            //update
            if (toDo.Id > 0)
            {
                var itemToBeUpdated = Data.SingleOrDefault(item => item.Id == toDo.Id);
                if (itemToBeUpdated != null)
                {
                    Data.Remove(itemToBeUpdated);

                    itemToBeUpdated.Title = toDo.Title;
                    itemToBeUpdated.Description = toDo.Description;
                    itemToBeUpdated.MailTo = toDo.MailTo;
                    itemToBeUpdated.Priority = toDo.Priority;

                    Data.Add(itemToBeUpdated);
                }
                return RedirectToAction("Listing", "Listing", Data);
            }

            //add new
            toDo.Id = Data.Last().Id + 1;
            Data.Add(toDo);
            return RedirectToAction("Listing", "Listing", Data);
        }
Example #2
0
        public ToDoViewModel()
        {
            toDo = new ToDo();
            toDoFilterItems = new List<SelectListItem>();       //Drop down list

            toDoFilterItems.Add(new SelectListItem { Text = "Complete", Value = "Complete" });
            toDoFilterItems.Add(new SelectListItem { Text = "Todo", Value = "Todo" });
            toDoFilterItems.Add(new SelectListItem { Text = "Show all", Value = "Show all" });
         
        }
Example #3
0
        public ActionResult Create( ToDo toDo)
        {
            toDo.Created = DateTime.UtcNow;
            if (ModelState.IsValid)
            {
                db.ToDoes.Add(toDo);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(toDo);
        }
 public ActionResult AddTodo(ToDo toDo)
 {
     return View(toDo ?? new ToDo());
 }
Example #5
0
 public ActionResult Edit(ToDo toDo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toDo).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(toDo);
 }