Beispiel #1
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/tasks"] = _ => {
         List <Task> allTasks = Task.GetAll();
         return(View["tasks.cshtml", allTasks]);
     };
     Get["/tasks/new"] = _ => {
         return(View["task_form.cshtml"]);
     };
     Post["/tasks"] = _ => {
         Task        newTask  = new Task(Request.Form["new-task"]);
         List <Task> allTasks = Task.GetAll();
         if (allTasks.Count == 0)
         {
             return(View["index.cshtml"]);
         }
         else
         {
             return(View["tasks.cshtml", allTasks]);
         }
     };
     Get["/tasks/{id}"] = parameters => {
         Task task = Task.Find(parameters.id);
         return(View["/task.cshtml", task]);
     };
     Get["/tasks/remove/{id}"] = parameters => {
         Task.RemoveTask(parameters.id);
         return(View["/remove.cshtml"]);
     };
 }
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/tasks"] = _ => {
                List <Task> allTasks = Task.GetAll();
                return(View["tasks.cshtml", allTasks]);
            };

            Get["/tasks/new"] = _ => {
                return(View["add_new_task"]);
            };

            Post["/tasks/added"] = _ => {
                Task newTask = new Task(Request.Form["description"]);
                newTask.Save();
                return(View["task_created.cshtml", newTask]);
            };

            Get["/tasks/{id}"] = parameters => {
                Task selectedTask = Task.Find(parameters.id);
                return(View["task_details.cshtml", selectedTask]);
            };

            Get["/tasks/cleared"] = _ => {
                Task.DeleteAll();
                return(View["tasks_deleted.cshtml"]);
            };
        }
Beispiel #3
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/tasks"] = _ => {
         List <Task> allTasks = Task.GetAll();
         return(View["tasks.cshtml", allTasks]);
     };
     Get["/tasks/new"] = _ => {
         return(View["task_form.cshtml"]);
     };
     Get["/tasks/{id}"] = parameters => {
         Task task = Task.Find(parameters.id);
         return(View["/task.cshtml", task]);
     };
     Post["/tasks"] = _ => {
         Task        newTask  = new Task(Request.Form["new-task"]);
         List <Task> allTasks = Task.GetAll();
         return(View["tasks.cshtml", allTasks]);
     };
     Post["/clear"] = _ => {
         List <Task> allTasks = Task.GetAll();
         Task.ClearAll();
         return(View["tasks.cshtml", allTasks]);
     };
 }
Beispiel #4
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/tasks"] = _ => {
         var AllTasks = Task.All();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/tasks/new"] = _ => {
         return(View["task_form.cshtml"]);
     };
     Post["/tasks"] = _ => {
         var NewTask  = new Task(Request.Form["new-task"]);
         var AllTasks = Task.All();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/tasks/{id}"] = parameters => {
         var task = Task.Find(parameters.id);
         return(View["/task.cshtml", task]);
     };
     // Post["/tasks/clear"] = _ => {
     //   Task.DeleteAll();
     //   return View["tasks_cleared.cshtml"];
     // };
 }
Beispiel #5
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/tasks"] = _ => {
                var AllTasks = Task.All();
                return(View["tasks.cshtml", AllTasks]);
            };
            Get["/tasks/new"] = _ => {
                return(View["task_form.cshtml"]);
            };
            Get["/tasks/{id}"] = parameters => {
                var SelectedTask = Task.Find(parameters.id);
                return(View["/task.cshtml", SelectedTask]);
            };
            Get["/categories"] = _ => {
                var AllCategories = Category.All();
                return(View["categories.cshtml", AllCategories]);
            };
            Get["/categories/new"] = _ => {
                return(View["category_form.cshtml"]);
            };
            Post["/categories"] = _ => {
                var NewCategory   = new Category(Request.Form["category-name"]);
                var AllCategories = Category.All();
                return(View["categories.cshtml", AllCategories]);
            };
            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var SelectedCategory = Category.Find(parameters.id);
                var CategoryTasks    = SelectedCategory.GetTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", CategoryTasks);
                return(View["/category.cshtml", model]);
            };
            Get["/categories/{id}/tasks/new"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> AllTasks = SelectedCategory.GetTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", AllTasks);
                return(View["/category_tasks_form.cshtml", model]);
            };
            Post["/tasks"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(Request.Form["category-id"]);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                string      TaskDescription       = Request.Form["task-description"];
                Task        NewTask = new Task(TaskDescription);
                CategoryTasks.Add(NewTask);

                model.Add("tasks", CategoryTasks);
                model.Add("category", SelectedCategory);

                return(View["/category.cshtml", model]);
            };
        }
        public void Test_Find_FindsTaskInDatabase()
        {
            Task testTask = new Task("Mow the lawn", 1, DateTime.Today);

            testTask.Save();
            Task foundTask = Task.Find(testTask.GetId());

            Assert.Equal(testTask, foundTask);
        }
Beispiel #7
0
        public void Test_Find_FindsTaskInDatabase()
        {
            Task testTask = new Task("Mow the lawn");

            testTask.Save();
            System.Console.WriteLine(testTask.GetId());
            Task foundTask = Task.Find(testTask.GetId());

            Assert.Equal(testTask, foundTask);
        }
Beispiel #8
0
        public void Test_Find_FindsTaskInDatabase()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn");

            testTask.Save();

            Task foundTask = Task.Find(testTask.GetId());

            Assert.Equal(testTask, foundTask);
        }
Beispiel #9
0
        public void Test_FindFindsTaskInDatabase()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn", 1, "01-02-2017");

            testTask.Save();

            //Act
            Task foundTask = Task.Find(testTask.GetId());

            //Assert
            Assert.Equal(testTask, foundTask);
        }
Beispiel #10
0
        public void Test_Find_FindTaskInDatabase()
        {
            //Arrange
            Task newTask = new Task("Chores", "2000-01-01");

            newTask.Save();

            //Act
            Task foundTask = Task.Find(newTask.GetId());

            //Assert
            Assert.Equal(newTask, foundTask);
        }
        public void Test_FindFindsTaskInDatabase()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn");

            testTask.Save();

            //Act
            Task result = Task.Find(testTask.GetId());

            //Assert
            Assert.Equal(testTask, result);
        }
        public void Test_FindFindsTaskInDatabase()
        {
            DateTime time = new DateTime(2016, 08, 08);
            //Arrange
            Task testTask = new Task("Mow the lawn", time);

            testTask.Save();

            //Act
            Task foundTask = Task.Find(testTask.GetId());

            //Assert
            Assert.Equal(testTask, foundTask);
        }
Beispiel #13
0
        public void Test_Find_FindsTaskInDatabase()
        {
            //Arrange
            DateTime myDate   = new DateTime(1999, 6, 4);
            Task     testTask = new Task("Mow the lawn", 1, myDate);

            testTask.Save();

            //Act
            Task foundTask = Task.Find(testTask.GetId());

            //Assert
            Assert.Equal(testTask, foundTask);
        }
        public void Test_Find_FindsTaskInDatabase()
        {
            //Arrange
            DateTime date1    = new DateTime(2008, 4, 10);
            Task     testTask = new Task("Mow the lawn", date1);

            testTask.Save();

            //Act
            Task foundTask = Task.Find(testTask.GetId());

            //Assert
            Assert.Equal(testTask, foundTask);
        }
        public void Test_DueDate_SavesInRightFormat()
        {
            //Arrange
            string testDate = "2017-02-17";
            string taskDate;
            Task   testTask = new Task("Mow the lawn", "2017-02-17");

            testTask.Save();

            //Act
            Task foundTask = Task.Find(testTask.GetId());

            taskDate = foundTask.GetDueDate();
            //Assert
            Assert.Equal(testDate, taskDate);
        }
Beispiel #16
0
        public void Test_FindFindsTaskInDatabase()
        {
            //Arrange
            Console.WriteLine("TEST");
            Task testTask = new Task("Mow the lawn", 1);

            Console.WriteLine("TEST2");
            testTask.Save();

            //Act
            Console.WriteLine(testTask.GetId());
            Console.WriteLine("TEST 3");
            Task foundTask = Task.Find(testTask.GetId());

            //Assert
            Console.WriteLine("TEST4");
            Assert.Equal(testTask, foundTask);
        }
Beispiel #17
0
 public HomeModule()
 {
     Get["/"] = _ => View["add_new_task.cshtml"];
     Get["/view_all_tasks"] = _ => {
         List <Task> allTasks = Task.GetAll();
         return(View["view_all_tasks.cshtml", allTasks]);
     };
     Post["/task_added"] = _ => {
         Task newTask = new Task(Request.Form["new-task"]);
         return(View["task_added.cshtml", newTask]);
     };
     Get["/tasks_cleared"] = _ => {
         Task.ClearAll();
         return(View["tasks_cleared.cshtml"]);
     };
     Get["/tasks/{id}"] = parameters => {
         Task task = Task.Find(parameters.id);
         return(View["/task.cshtml", task]);
     };
 }
Beispiel #18
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };
            Post["/tasks"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    selectedCategory      = Category.Find(Request.Form["category-id"]);
                List <Task> categoryTasks         = selectedCategory.GetTasks();
                string      taskDescription       = Request.Form["task-description"];
                Task        newTask = new Task(taskDescription);
                categoryTasks.Add(newTask);
                model.Add("tasks", categoryTasks);
                model.Add("category", selectedCategory);
                return(View["category.cshtml", model]);
            };
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };
            //Create a new task
            Get["/tasks/new"] = _ => {
                return(View["tasks_form.cshtml"]);
            };
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };

            //Create a new category
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };

            Post["task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };
            Post["category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };
            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };
            Get["/categories/{id}/tasks/new"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    selectedCategory      = Category.Find(parameters.id);
                List <Task> allTasks = selectedCategory.GetTasks();
                model.Add("category", selectedCategory);
                model.Add("tasks", allTasks);
                return(View["category_tasks_form.cshtml", model]);
            };
        }
Beispiel #19
0
        public HomeModule()
        {
            Get["/"]      = _ => View["index.cshtml"];
            Get["/tasks"] = _ => {
                List <Task> allTasks = Task.GetAll();
                return(View["tasks.cshtml", allTasks]);
            };
            Get["/tasks/new"] = _ => {
                return(View["task_form.cshtml"]);
            };
            Get["/task/{id}"] = parameters => {
                Task task = Task.Find(parameters.id);
                return(View["/task.cshtml", task]);
            };
            Post["/tasks_cleared"] = _ => {
                Task.ClearAll();
                return(View["tasks_cleared.cshtml"]);
            };

            Get["/categories"] = _ => {
                var allCategories = Category.GetAll();
                return(View["categories.cshtml", allCategories]);
            };

            Get["/categories/new"] = _ => {
                return(View["category_form.cshtml"]);
            };

            Post["/categories"] = _ => {
                var newCategory   = new Category(Request.Form["category-name"]);
                var allCategories = Category.GetAll();
                return(View["categories.cshtml", allCategories]);
            };

            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var         selectedCategory      = Category.Find(parameters.id);
                List <Task> categoryTasks         = selectedCategory.GetTasks();
                model.Add("category", selectedCategory);
                model.Add("tasks", categoryTasks);
                return(View["category.cshtml", model]);
            };

            Get["/categories/{id}/tasks/new"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    selectedCategory      = Category.Find(parameters.id);
                List <Task> allTasks = selectedCategory.GetTasks();
                model.Add("category", selectedCategory);
                model.Add("tasks", allTasks);
                return(View["category_tasks_form.cshtml", model]);
            };

            Post["/tasks"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    selectedCategory      = Category.Find(Request.Form["category-id"]);
                List <Task> categoryTasks         = selectedCategory.GetTasks();
                string      taskDescription       = Request.Form["task-description"];
                Task        newTask = new Task(taskDescription);
                categoryTasks.Add(newTask);
                model.Add("tasks", categoryTasks);
                model.Add("category", selectedCategory);
                return(View["category.cshtml", model]);
            };
        }
Beispiel #20
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };
            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };
            Get["/tasks/new"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["tasks_form.cshtml", AllCategories]);
            };
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], Request.Form["dueDate"], Request.Form["completed"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };
            Post["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["index.cshtml"]);
            };
            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                var         SelectedCategory      = Category.Find(parameters.id);
                var         CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("tasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };

            Post["/task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };
            Post["/category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };

            Get["tasks/completed"] = _ => {
                List <Task> updatedTasks = Task.CompletedTasks();
                return(View["completed_tasks.cshtml", updatedTasks]);
            };

            Get["tasks/update/{id}"] = _ => {
                List <Task> updatedTasks = Task.CompletedTasks();
                return(View["completed_tasks.cshtml", updatedTasks]);
            };

            Patch["tasks/update/{id}"] = parameters => {
                Task completedTask = Task.Find(parameters.id);
                completedTask.MarkComplete();
                List <Task> updatedTasks = Task.CompletedTasks();
                return(View["completed_tasks.cshtml", updatedTasks]);
            };

            Post["/tasks/sorted"] = _ => {
                List <Task> AllTasks = Task.OrderByDate();
                return(View["tasks.cshtml", AllTasks]);
            };
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };
            Get["/tasks/new"] = _ => {
                return(View["tasks_form.cshtml"]);
            };
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };

            //Create a new category
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };

            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };

            Post["task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };
            Post["category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };



            // Get["/categories/new"] = _ => {
            //   return View["categories_form.cshtml"];
            // };
            // Post["/categories/new"] = _ => {
            //   Category newCategory = new Category(Request.Form["category-name"]);
            //   newCategory.Save();
            //   return View["success.cshtml"];
            // };
            // Post["/categories/clear"] = _ => {
            //   Category.DeleteAll();
            //   // return View["cleared.cshtml"];  no cleared.cshtml in lesson plan, switched to success.cshtml
            //   return View["success.cshtml"];
            // };
            // Get["category/edit/{id}"] = parameters => {
            //   Category SelectedCategory = Category.Find(parameters.id);
            //   return View["category_edit.cshtml", SelectedCategory];
            // };
            // Patch["category/edit/{id}"] = parameters => {
            //   Category SelectedCategory = Category.Find(parameters.id);
            //   SelectedCategory.Update(Request.Form["category-name"]);
            //   return View["success.cshtml"];
            // };
            // Get["category/delete/{id}"] = parameters => {
            //   Category SelectedCategory = Category.Find(parameters.id);
            //   return View["category_delete.cshtml", SelectedCategory];
            // };
            // Delete["category/delete/{id}"] = parameters => {
            //   Category SelectedCategory = Category.Find(parameters.id);
            //   SelectedCategory.Delete();
            //   return View["success.cshtml"];
            // };
            // Get["/tasks/new"] = _ => {
            //   List<Category> AllCategories = Category.GetAll();
            //   return View["tasks_form.cshtml", AllCategories];
            // };
            // Post["/tasks/new"] = _ => {
            //   Task newTask = new Task(Request.Form["task-description"], Request.Form["category-id"]);
            //   newTask.Save();
            //   return View["success.cshtml"];
            // };
            //
            // Post["/tasks/clear"] = _ => {
            //   Task.DeleteAll();
            //   return View["success.cshtml"];
            //   // return View["cleared.cshtml"];  no cleared.cshtml in lesson plan, switched to success.cshtml
            // };
            // Get["/categories/{id}"] = parameters => {
            //   Dictionary<string, object> model = new Dictionary<string, object>();
            //   var SelectedCategory = Category.Find(parameters.id);
            //   var CategoryTasks = SelectedCategory.GetTasks();
            //   model.Add("category", SelectedCategory);
            //   model.Add("tasks", CategoryTasks);
            //   return View["category.cshtml", model];
            // };
        }
Beispiel #22
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Category> AllCategories = Category.GetAll();
         return(View["index.cshtml", AllCategories]);
     };
     Get["/tasks"] = _ => {
         List <Task> AllTasks = Task.GetAll();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/categories"] = _ => {
         List <Category> AllCategories = Category.GetAll();
         return(View["categories.cshtml", AllCategories]);
     };
     Get["/categories/new"] = _ => {
         return(View["categories_form.cshtml"]);
     };
     Post["/categories/new"] = _ => {
         Category newCategory = new Category(Request.Form["category-name"]);
         newCategory.Save();
         return(View["success.cshtml"]);
     };
     Get["/tasks/new"] = _ => {
         List <Category> AllCategories = Category.GetAll();
         return(View["tasks_form.cshtml", AllCategories]);
     };
     Post["/tasks/new"] = _ => {
         Task newTask = new Task(Request.Form["task-description"], Request.Form["task-date"]);
         newTask.Save();
         return(View["success.cshtml"]);
     };
     Post["/tasks/delete"] = _ => {
         Task.DeleteAll();
         return(View["tasks_cleared.cshtml"]);
     };
     Post["/categories/clear"] = _ => {
         Category.DeleteAll();
         Task.DeleteAll();
         return(View["categories_cleared.cshtml"]);
     };
     Get["/tasks/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Task            SelectedTask      = Task.Find(parameters.id);
         List <Category> TaskCategories    = SelectedTask.GetCategories();
         List <Category> AllCategories     = Category.GetAll();
         model.Add("task", SelectedTask);
         model.Add("taskCategories", TaskCategories);
         model.Add("allCategories", AllCategories);
         return(View["task.cshtml", model]);
     };
     Get["/categories/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Category    SelectedCategory      = Category.Find(parameters.id);
         List <Task> CategoryTasks         = SelectedCategory.GetTasks();
         List <Task> AllTasks = Task.GetAll();
         model.Add("category", SelectedCategory);
         model.Add("categoryTasks", CategoryTasks);
         model.Add("allTasks", AllTasks);
         return(View["category.cshtml", model]);
     };
     Patch["/categories/finished/{id}"] = parameters => {
         Task isTaskDone = Task.Find(parameters.id);
         isTaskDone.UpdateDone(1);
         return(View["index.cshtml"]);
     };
     Post["/task/add_category"] = _ => {
         Category category = Category.Find(Request.Form["category-id"]);
         Task     task     = Task.Find(Request.Form["task-id"]);
         task.AddCategory(category);
         return(View["success.cshtml"]);
     };
     Post["/category/add_task"] = _ => {
         Category category = Category.Find(Request.Form["category-id"]);
         Task     task     = Task.Find(Request.Form["task-id"]);
         category.AddTask(task);
         return(View["success.cshtml"]);
     };
     // Get["/category/list"] = _ => {
     //     Console.WriteLine(Request.Query("house work"));
     //     Dictionary<string, object> model = new Dictionary<string, object>();
     //     List<Category> allCategories = Category.GetAll();
     //     foreach(var category in allCategories)
     //     {
     //         if(Request.Form[category.GetName()] != null)
     //         {
     //             List<Task> listTasks = category.GetTasks();
     //             model.Add(category.GetName(), listTasks);
     //         }
     //     }
     //     foreach(KeyValuePair<string, object> entry in model)
     //     {
     //         foreach(Task thisTask in entry.Value as List<Task>)
     //         {
     //             Console.WriteLine(thisTask.GetDescription());
     //         }
     //     }
     //     return View["categories_multiple.cshtml", model];
     // };
     Get["/category/edit/{id}"] = parameters => {
         Category SelectedCategory = Category.Find(parameters.id);
         return(View["category_edit.cshtml", SelectedCategory]);
     };
     Patch["/category/edit/{id}"] = parameters => {
         Category SelectedCategory = Category.Find(parameters.id);
         SelectedCategory.Update(Request.Form["category-name"]);
         return(View["success.cshtml"]);
     };
     Get["/category/delete/{id}"] = parameters => {
         Category SelectedCategory = Category.Find(parameters.id);
         return(View["category_delete.cshtml", SelectedCategory]);
     };
     Delete["/category/delete/{id}"] = parameters => {
         Category SelectedCategory = Category.Find(parameters.id);
         SelectedCategory.Delete();
         return(View["success.cshtml"]);
     };
 }
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };
            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };
            Get["/tasks/new"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["tasks_form.cshtml", AllCategories]);
            };
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], new DateTime(Request.Form["due-date"]));
                newTask.Save();
                return(View["success.cshtml"]);
            };
            Delete["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["cleared.cshtml"]);
            };
            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };
            Post["task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };
            Post["category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };
            Get["/tasks/complete"] = _ => {
                List <Task> completedTasks = Task.GetAll(true);
                return(View["tasks.cshtml", completedTasks]);
            };
            Get["/tasks/incomplete"] = _ => {
                List <Task> incompleteTasks = Task.GetAll(false);
                return(View["tasks.cshtml", incompleteTasks]);
            };
            Patch["/tasks/{id}/complete"] = parameters => {
                Task.Complete(parameters.id);
                List <Task> allTasks = Task.GetAll();
                return(View["tasks.cshtml", allTasks]);
                // List<Category> AllCategories = Category.GetAll();
                // return View["index.cshtml", AllCategories];
            };
        }
Beispiel #24
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/categories"] = _ => {
         var allCategories = Category.GetAll();
         return(View["categories.cshtml", allCategories]);
     };
     Get["/categories/new"] = _ => {
         return(View["category_form.cshtml"]);
     };
     Post["/categories"] = _ => {
         var newCategory   = new Category(Request.Form["category-name"]);
         var allCategories = Category.GetAll();
         return(View["categories.cshtml", allCategories]);
     };
     Get["/categories/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var selectedCategory = Category.Find(parameters.id);
         var categoryTasks    = selectedCategory.GetTasks();
         model.Add("category", selectedCategory);
         model.Add("tasks", categoryTasks);
         return(View["category.cshtml", model]);
     };
     Get["/clear_categories"] = _ => {
         Category.Clear();
         return(View ["index.cshtml"]);
     };
     //view a task
     Get["/categories/{id}/task/{taskId}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Category selectedCategory         = Category.Find(parameters.id);
         Task     returnTask = Task.Find(parameters.taskId);
         model.Add("category", selectedCategory);
         model.Add("task", returnTask);
         return(View["task.cshtml", model]);
     };
     //jill's delete task
     Post["/deleteTask/{id}/task/{taskId}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var         selectedCategory      = Category.Find(parameters.id);
         List <Task> allTasks = Task.GetAll();
         Task        task     = allTasks[parameters.taskId - 1];
         task.ClearTask();
         // selectedCategory.RemoveTask(task);
         var categoryTasks = selectedCategory.GetTasks();
         model.Add("category", selectedCategory);
         model.Add("tasks", categoryTasks);
         return(View["category.cshtml", model]);
     };
     //deltet a task
     Get["/delete/{id}/task/{taskId}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Category    selectedCategory      = Category.Find(parameters.id);
         List <Task> allTasks = Task.GetAll();
         Task        task     = allTasks[parameters.taskId - 1];
         selectedCategory.RemoveTask(task);
         model.Add("category", selectedCategory);
         model.Add("tasks", allTasks);
         return(View["category.cshtml", model]);
     };
     Get["/categories/{id}/tasks/new"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Category    selectedCategory      = Category.Find(parameters.id);
         List <Task> allTasks = selectedCategory.GetTasks();
         model.Add("category", selectedCategory);
         model.Add("tasks", allTasks);
         return(View["category_tasks_form.cshtml", model]);
     };
     Post["/categories/{id}/task/{taskId}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var  selectedCategory             = Category.Find(parameters.id);
         var  categoryTasks = selectedCategory.GetTasks();
         Task task          = categoryTasks[parameters.taskId - 1];
         task.SetDescription(Request.Form["edit"]);
         model.Add("category", selectedCategory);
         model.Add("tasks", categoryTasks);
         return(View["category.cshtml", model]);
     };
     Post["/tasks"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Category    selectedCategory      = Category.Find(Request.Form["category-id"]);
         List <Task> categoryTasks         = selectedCategory.GetTasks();
         string      taskDescription       = Request.Form["task-description"];
         Task        newTask = new Task(taskDescription);
         categoryTasks.Add(newTask);
         model.Add("tasks", categoryTasks);
         model.Add("category", selectedCategory);
         return(View["category.cshtml", model]);
     };
 }
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };

            Get["/tasks/completed"] = _ => {
                List <Task> CompletedTasks = Task.GetCompleted();
                return(View["tasks_completed.cshtml", CompletedTasks]);
            };

            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            //Create a new category
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };

            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };

            //Create a new task
            Get["/tasks/new"] = _ => {
                return(View["tasks_form.cshtml"]);
            };

            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], Request.Form["completed"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };

            Post["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };

            Post["task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };

            Post["category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };

            Get["tasks/{id}/edit"] = parameters => {
                Task SelectedTask = Task.Find(parameters.id);
                return(View["task_update_form.cshtml", SelectedTask]);
            };

            Patch["tasks/{id}/updated"] = parameters => {
                Task SelectedTask = Task.Find(parameters.id);
                SelectedTask.UpdateProperties(Request.Form["new-task-description"], Request.Form["new-completed"]);
                return(View["success.cshtml", SelectedTask]);
            };

            Post["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["success.cshtml"]);
            };
        }
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                List <Category> AllCategories = Category.GetAll();
                return(View ["index.cshtml", AllCategories]);
            };

            Get["/tasks"] = _ =>
            {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };

            Get["/categories"] = _ =>
            {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            Get["/categories/new"] = _ =>
            {
                return(View["categories_form.cshtml"]);
            };

            Post["/categories/new"] = _ =>
            {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };

            Get["/tasks/new"] = _ =>
            {
                List <Category> AllCategories = Category.GetAll();
                return(View["tasks_form.cshtml", AllCategories]);
            };

            Post["/tasks/new"] = _ =>
            {
                string date = Request.Form["task-date"];
                Console.WriteLine(date);
                Task newTask = new Task(Request.Form["task-description"], Request.Form["task-date"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };

            Post["/tasks/delete"] = _ =>
            {
                Task.DeleteAll();
                return(View["cleared.cshtml"]);
            };
            Get["tasks/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                return(View["task.cshtml", model]);
            };

            Get["categories/{id}"] = parameters =>
            {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };

            Post["/categories/delete"] = _ =>
            {
                Category.DeleteAll();
                Task.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            Post["task/add_category"] = _ =>
            {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                return(View["success.cshtml"]);
            };
            Post["category/add_task"] = _ =>
            {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };
        }
Beispiel #27
0
        public HomeModule()
        {
            Get["/"] = _ => {
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };
            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            };

            //Create a new task
            Get["/tasks/new"] = _ => {
                return(View["tasks_form.cshtml"]);
            };
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], Request.Form["date"]);
                newTask.Save();
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };

            //Create a new category
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };

            Get["tasks/{id}"] = parameters =>
            {
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                Task            targetTask     = Task.Find(parameters.id);
                List <Category> taskCategories = targetTask.GetCategories();
                List <Category> allCategories  = Category.GetAll();
                passedModel.Add("task", targetTask);
                passedModel.Add("taskCategories", taskCategories);
                passedModel.Add("allCategories", allCategories);
                return(View["task.cshtml", passedModel]);
            };
            Delete["tasks/{id}"] = parameters =>
            {
                Task targetTask = Task.Find(parameters.id);
                targetTask.Delete();
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };
            Patch["/tasks/{id}"] = parameters =>
            {
                string newName = Request.Form["new-task-name"];
                string newDate = Request.Form["new-task-date"];
                Task.Find(parameters.id).Update(newName, newDate);
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };

            Get["categories/{id}"] = parameters =>
            {
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                Category    targetCategory = Category.Find(parameters.id);
                List <Task> categoryTasks  = targetCategory.GetTasks();
                List <Task> allTasks       = Task.GetAll();
                passedModel.Add("category", targetCategory);
                passedModel.Add("categoryTasks", categoryTasks);
                passedModel.Add("allTasks", allTasks);
                return(View["category.cshtml", passedModel]);
            };
            Delete["categories/{id}"] = parameters =>
            {
                Category targetCategory = Category.Find(parameters.id);
                targetCategory.Delete();
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };
            Patch["/categories/{id}"] = parameters =>
            {
                string newName = Request.Form["new-category-name"];
                Category.Find(parameters.id).Update(newName);
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };

            Post["task/add_category"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };
            Post["category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                Dictionary <string, object> passedModel = new Dictionary <string, object>()
                {
                };
                passedModel["categories"] = Category.GetAll();
                passedModel["tasks"]      = Task.GetAll();
                return(View["index.cshtml", passedModel]);
            };
            //
            // Get["/categories"] = _ => {
            //   var allCategories = Category.GetAll();
            //   return View["categories.cshtml", allCategories];
            // };
            // Post["/categories"] = _ => {
            //   var newCategory = new Category(Request.Form["category-name"]);
            //   newCategory.Save();
            //   var allCategories = Category.GetAll();
            //   return View["categories.cshtml", allCategories];
            // };
            //
            // Get["/categories/new"] = _ => {
            //   return View["category_form.cshtml"];
            // };
            //
            // Get["/categories/{id}"] = parameters => {
            //   Dictionary<string, object> model = new Dictionary<string, object>();
            //   var selectedCategory = Category.Find(parameters.id);
            //   var categoryTasks = selectedCategory.GetTasks();
            //   model.Add("category", selectedCategory);
            //   model.Add("tasks", categoryTasks);
            //   return View["category.cshtml", model];
            // };
            //
            // Get["/categories/{id}/tasks/new"] = parameters => {
            //   Dictionary<string, object> model = new Dictionary<string, object>();
            //   Category selectedCategory = Category.Find(parameters.id);
            //   List<Task> allTasks = selectedCategory.GetTasks();
            //   model.Add("category", selectedCategory);
            //   model.Add("tasks", allTasks);
            //   return View["category_tasks_form.cshtml", model];
            // };
            //
            // Post["/delete/task/{categoryId}/{taskId}"] = parameters => {
            //     Task targetTask = Task.Find(parameters.taskId);
            //     targetTask.Delete();
            //     Dictionary<string, object> model = new Dictionary<string, object>();
            //     var selectedCategory = Category.Find(parameters.categoryId);
            //     var categoryTasks = selectedCategory.GetTasks();
            //     model.Add("category", selectedCategory);
            //     model.Add("tasks", categoryTasks);
            //     return View["category.cshtml", model];
            // };
            //
            // Post["/delete/category/{categoryId}"] = parameters => {
            //     Category targetCategory = Category.Find(parameters.categoryId);
            //     targetCategory.Delete();
            //     List<Category> allCategories = Category.GetAll();
            //     return View["categories.cshtml", allCategories];
            // };
            //
            // Post["/tasks"] = _ => {
            //   Dictionary<string, object> model = new Dictionary<string, object>();
            //   Category selectedCategory = Category.Find(Request.Form["category-id"]);
            //   string taskDescription = Request.Form["task-description"];
            //   int newCategoryId = int.Parse(Request.Form["category-id"]);
            //   string newDate = Request.Form["date"];
            //   Task newTask = new Task(taskDescription, newCategoryId, newDate);
            //   newTask.Save();
            //   List<Task> categoryTasks = selectedCategory.GetTasks();
            //   model.Add("tasks", categoryTasks);
            //   model.Add("category", selectedCategory);
            //   return  View["category.cshtml", model];
            // };
        }
Beispiel #28
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            }; //homepage with links to view all tasks and all categories
            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            }; //page view all tasks
            Get["/categories"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            }; //page view all categories
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };
            Get["/tasks/new"] = _ => {
                return(View["tasks_form.cshtml"]);
            }; //returns form to add new task
            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], Request.Form["category-id"]);
                newTask.Save();
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            }; //posts from form adding new task
            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            }; //returns form to add new task
            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            }; //posts from form adding new category
            Get["/tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                model.Add("isCompleted", SelectedTask);
                return(View["task.cshtml", model]);
            }; //returns individual instance of task
            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            }; //returns individual instance of category
            Post["/task/{id}/add_category"] = parameters => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                task.AddCategory(category);
                Dictionary <string, object> model          = new Dictionary <string, object>();
                List <Category>             taskCategories = task.GetCategories();
                List <Category>             allCategories  = Category.GetAll();
                model.Add("task", task);
                model.Add("taskCategories", taskCategories);
                model.Add("allCategories", allCategories);
                model.Add("isCompleted", task);
                return(View["index.cshtml", model]);
            }; //posts from form adding category
            Post["/category/{id}/add_task"] = parameters => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            }; //posts from form adding task to category page
            Get["/task/{id}/completed"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object> {
                };
                Task   SelectedTask  = Task.Find(parameters.id);
                string taskCompleted = Request.Query["task-completed"];
                model.Add("form-type", taskCompleted);
                model.Add("task", SelectedTask);
                return(View["completed.cshtml", model]);
            }; //returns page confirming task completion

            Patch["/task/{id}/completed"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> AllCategories     = Category.GetAll();
                SelectedTask.Update(true);
                model.Add("task", SelectedTask);
                model.Add("taskCategories", TaskCategories);
                model.Add("allCategories", AllCategories);
                model.Add("isCompleted", SelectedTask);
                return(View["task.cshtml", model]);
            }; //returns category page with task marked completed

            Get["/category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                return(View["category_edit.cshtml", SelectedCategory]);
            }; //edit individual category
            Patch["/category/edit/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category SelectedCategory         = Category.Find(parameters.id);
                SelectedCategory.Update(Request.Form["category-name"]);
                List <Task> CategoryTasks = SelectedCategory.GetTasks();
                List <Task> AllTasks      = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            }; //posts from editing individual category
            Get["/category/delete/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                return(View["category_delete.cshtml", SelectedCategory]);
            }; //delete individual category
            Delete["/category/delete/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.Delete();
                List <Category> AllCategories = Category.GetAll();
                return(View["categories.cshtml", AllCategories]);
            }; //delete individual category
        }
Beispiel #29
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };

            Get["/tasks"] = _ => {
                List <Task> AllTasks = Task.GetAll();
                return(View["tasks.cshtml", AllTasks]);
            };

            Get["/categories"] = _ => {
                List <Category> allCategories = Category.GetAll();
                return(View["categories.cshtml", allCategories]);
            };

            Get["/categories/new"] = _ => {
                return(View["categories_form.cshtml"]);
            };

            Post["/categories/new"] = _ => {
                Category newCategory = new Category(Request.Form["category-name"]);
                newCategory.Save();
                return(View["success.cshtml"]);
            };

            Get["/tasks/new"] = _ => {
                return(View["tasks_form.cshtml"]);
            };

            Post["/tasks/new"] = _ => {
                Task newTask = new Task(Request.Form["task-description"], Request.Form["due-date"]);
                newTask.Save();
                return(View["success.cshtml"]);
            };

            Post["/tasks/delete"] = _ => {
                Task.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            Get["/categories/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Category    SelectedCategory      = Category.Find(parameters.id);
                List <Task> CategoryTasks         = SelectedCategory.GetTasks();
                List <Task> AllTasks = Task.GetAll();
                model.Add("category", SelectedCategory);
                model.Add("categoryTasks", CategoryTasks);
                model.Add("allTasks", AllTasks);
                return(View["category.cshtml", model]);
            };

            Get["tasks/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Task            SelectedTask      = Task.Find(parameters.id);
                List <Category> TaskCategories    = SelectedTask.GetCategories();
                List <Category> allCategories     = Category.GetAll();
                model.Add("task", SelectedTask);
                model.Add("TaskCategories", TaskCategories);
                model.Add("allCategories", allCategories);
                return(View["task.cshtml", model]);
            };

            Post["task/add_category"] = _ => {
                Category        category       = Category.Find(Request.Form["category-id"]);
                Task            task           = Task.Find(Request.Form["task-id"]);
                List <Category> taskCategories = task.GetCategories();
                bool            tracker        = false;
                foreach (Category thisCategory in taskCategories)
                {
                    if (category.GetName() == thisCategory.GetName())
                    {
                        tracker = true;
                    }
                }
                if (!tracker)
                {
                    task.AddCategory(category);
                }
                return(View["success.cshtml"]);
            };

            Post["category/add_task"] = _ => {
                Category category = Category.Find(Request.Form["category-id"]);
                Task     task     = Task.Find(Request.Form["task-id"]);
                category.AddTask(task);
                return(View["success.cshtml"]);
            };
        }