public IActionResult AddEditToDoItem(long id = 0) { var toDoItemVM = new ToDoItemFormVM(); if (id != 0) { var existingItem = _context.ToDoItems .Where(m => m.ID == id) .Single(); toDoItemVM = new ToDoItemFormVM(existingItem); } return(View(toDoItemVM)); }
public IActionResult AddEditToDoItem(ToDoItem item) { //don't process invalid data if (!ModelState.IsValid) { var itemFormVM = new ToDoItemFormVM(item); return(View("AddEditToDoItem", itemFormVM)); } if (item.ID == 0) { AddNewToDoItem(item); } else { UpdateToDoItem(item); } return(RedirectToAction("Index", "Home")); }