public void is_properly_updated()
        {
            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 item = _myContext.TodoListItem.FirstOrDefault(x => x.Id == insertItem.Id);

            item.Name = "Name2";
            _myContext.SaveChanges();
            var result = _myContext.TodoListItem.FirstOrDefault(x => x.Name == "Name1" && x.Id == insertItem.Id);

            Assert.AreEqual(result == null, true);
        }
示例#2
0
 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"));
 }
示例#3
0
        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"));
            }
        }
示例#4
0
        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"));
        }