示例#1
0
 public IActionResult Index()
 {
     using (var db = new ToDoDb())
     {
         var allTasks = db.Task.ToList();
         return(View(allTasks));
     }
 }
示例#2
0
 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));
     }
 }
示例#3
0
 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));
     }
 }
示例#4
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"));
 }
        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);
        }
示例#6
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"));
            }
        }
示例#7
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"));
        }
示例#8
0
 public ToDoRepository(ToDoDb db)
 {
     this.db = db;
 }