public IActionResult Index() { using (var db = new ToDoDb()) { var allTasks = db.Task.ToList(); return(View(allTasks)); } }
public IActionResult Details(int Id) { using (var db = new ToDoDb()) { var taskToDelete = db.Task.FirstOrDefault(t => t.Id == Id); if (taskToDelete == null) { return(RedirectToAction("Index")); } return(View(taskToDelete)); } }
public IActionResult Edit(int Id) { using (var db = new ToDoDb()) { var TaskToEdit = db.Task.FirstOrDefault(t => t.Id == Id); if (TaskToEdit == null) { return(RedirectToAction("Index")); } return(View(TaskToEdit)); } }
public IActionResult Delete(int Id) { using (var db = new ToDoDb()) { var oldTask = db.Task.FirstOrDefault(t => t.Id == Id); if (oldTask == null) { return(RedirectToAction("Index")); } db.Task.Remove(oldTask); db.SaveChanges(); } return(RedirectToAction("Index")); }
public void is_properly_add() { var _myContext = new ToDoDb(); var toDoList = new ToDoList(); _myContext.ToDoList.Add(toDoList); var insertItem = new TodoListItem { Name = "Name1", ToDoListId = toDoList.Id }; _myContext.TodoListItem.Add(insertItem); _myContext.SaveChanges(); var result = _myContext.TodoListItem.FirstOrDefault(x => x.Id == insertItem.Id); Assert.AreEqual(result == null, false); }
public IActionResult Edit(Task TaskToEdit) { using (var db = new ToDoDb()) { var oldTask = db.Task.FirstOrDefault(t => t.Id == TaskToEdit.Id); if (oldTask == null) { return(RedirectToAction("Index")); } oldTask.Title = TaskToEdit.Title; oldTask.Comments = TaskToEdit.Comments; if (string.IsNullOrEmpty(oldTask.Title) || string.IsNullOrEmpty(oldTask.Comments)) { return(RedirectToAction("Index")); } db.SaveChanges(); return(RedirectToAction("Index")); } }
public IActionResult Create(string title, string comments) { if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(comments)) //if (!(ModelState.IsValid)) { return(RedirectToAction("Index")); } Task NewTask = new Task { Title = title, Comments = comments, }; using (var db = new ToDoDb()) { db.Task.Add(NewTask); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ToDoRepository(ToDoDb db) { this.db = db; }