public ActionResult Create(TodoItemCreateViewModel model) { if (!ModelState.IsValid) { return View("New", new TodoItemCreateViewModel{Description = model.Description, Priority = model.Priority}); } var todo = new Todo { Id = 5, Description = model.Description, Priority = model.Priority, DoBy = DateTime.Now}; _service.AddTodoItem(1, todo); TempData["message"] = "Todo Item Created"; return RedirectToAction("Index"); }
public void AddTodoItem(int userId, Todo todo) { var user =_userRepository.Entities.First(u => u.Id == userId); user.Todos.Add(todo); _userRepository.Save(); }