public void Test_Delete_DeletesCategoryFromDatabase()
        {
            //Arrange
              string name1 = "Home stuff";
              Category testCategory1 = new Category(name1);
              testCategory1.Save();

              string name2 = "Work stuff";
              Category testCategory2 = new Category(name2);
              testCategory2.Save();
              DateTime fakeTime = new DateTime(2016, 1, 1);

              Task testTask1 = new Task("Mow the lawn", testCategory1.GetId(),fakeTime);
              testTask1.Save();
              DateTime fakeTime1 = new DateTime(2016, 1, 1);

              Task testTask2 = new Task("Send emails", testCategory2.GetId(),fakeTime1);
              testTask2.Save();

              //Act
              testCategory1.Delete();
              List<Category> resultCategories = Category.GetAll();
              List<Category> testCategoryList = new List<Category> {testCategory2};

              List<Task> resultTasks = Task.GetAll();
              List<Task> testTaskList = new List<Task> {testTask2};

              //Assert
              Assert.Equal(testCategoryList, resultCategories);
              Assert.Equal(testTaskList, resultTasks);
        }
    public void Test_FindFindsCategoryInDatabase()
    {
      //Arrange
      Category testCategory = new Category("Household chores");
      testCategory.Save();

      //Act
      Category foundCategory = Category.Find(testCategory.GetId());

      //Assert
      Assert.Equal(testCategory, foundCategory);
    }
        public void T3_Save_SavesCategoryToDatabase()
        {
            // Arrange
              Category testCategory = new Category("Household chores");
              testCategory.Save();

              // Act
              List<Category> result = Category.GetAll();
              List<Category> testList = new List<Category>{testCategory};

              // Assert
              Assert.Equal(testList, result);
        }
Ejemplo n.º 4
0
        public HomeModule()
        {
          //Index
            Get["/"] = _ => {
              List<Category> AllCategories = Category.GetAll();
              return View["index.cshtml", AllCategories];
            };
            //Get: Lists
            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["category-id"]);
              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>();
              var SelectedCategory = Category.Find(parameters.id);
              var CategoryTasks = SelectedCategory.GetTasks();
              model.Add("category", SelectedCategory);
              model.Add("tasks", CategoryTasks);
              return View["/category.cshtml", model];
            };
        }
    public void Test_SaveAssignsIdToCategoryObject()
    {
      //Arrange
      Category testCategory = new Category("Household chores");
      testCategory.Save();

      //Act
      Category savedCategory = Category.GetAll()[0];

      int result = savedCategory.GetId();
      int testId = testCategory.GetId();

      //Assert
      Assert.Equal(testId, result);
    }
Ejemplo n.º 6
0
        public void Test_AddCategory_AddsCategoryToTask()
        {
            //Arrange
              Task testTask = new Task("Mow the lawn", new DateTime(2016, 2, 2), false);
              testTask.Save();

              Category testCategory = new Category("Home stuff");
              testCategory.Save();

              //Act
              testTask.AddCategory(testCategory);

              List<Category> result = testTask.GetCategories();
              List<Category> testList = new List<Category>{testCategory};

              //Assert
              Assert.Equal(testList, result);
        }
Ejemplo n.º 7
0
        public void Test18_GetCategories_ReturnsAllTaskCategories()
        {
            DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask = new Task("Mow the lawn",testTime);
              testTask.Save();

              Category testCategory1 = new Category("Home Stuff");
              testCategory1.Save();

              Category testCategory2 = new Category("Work Stuff");
              testCategory2.Save();

              testTask.AddCategory(testCategory1);
              List<Category> result = testTask.GetCategories();
              List<Category> testList= new List<Category>{testCategory1};

              Assert.Equal(testList,result);
        }
Ejemplo n.º 8
0
        public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
        {
            //Arrange
              Task testTask = new Task("Mow the lawn", false);
              testTask.Save();

              string testName = "Home stuff";
              Category testCategory = new Category(testName);
              testCategory.Save();

              //Act
              testCategory.AddTask(testTask);
              testCategory.Delete();

              List<Category> resultTaskCategories = testTask.GetCategories();
              List<Category> testTaskCategories = new List<Category> {};

              //Assert
              Assert.Equal(testTaskCategories, resultTaskCategories);
        }
Ejemplo n.º 9
0
        public void Test_Delete_DeletesTaskAssociationsFromDatabase()
        {
            //Arrange
              Category testCategory = new Category("Home stuff");
              testCategory.Save();

              string testDescription = "Mow the lawn";
              Task testTask = new Task(testDescription, new DateTime(2016, 2, 2));
              testTask.Save();

              //Act
              testTask.AddCategory(testCategory);
              testTask.Delete();

              List<Task> resultCategoryTasks = testCategory.GetTasks();
              List<Task> testCategoryTasks = new List<Task> {};

              //Assert
              Assert.Equal(testCategoryTasks, resultCategoryTasks);
        }
Ejemplo n.º 10
0
        public void Test_AddTask_AddsTaskToCategory()
        {
            //Arrange
              Category testCategory = new Category("Household chores");
              testCategory.Save();

              Task testTask = new Task("Mow the lawn", false);
              testTask.Save();

              Task testTask2 = new Task("Water the garden", false);
              testTask2.Save();

              //Act
              testCategory.AddTask(testTask);
              testCategory.AddTask(testTask2);

              List<Task> result = testCategory.GetTasks();
              List<Task> testList = new List<Task>{testTask, testTask2};

              //Assert
              Assert.Equal(testList, result);
        }
        public void Delete_DeletesCategoryAssociationsFromDatabase_CategoryList()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn");

            testTask.Save();

            string   testName     = "Home stuff";
            Category testCategory = new Category(testName);

            testCategory.Save();

            //Act
            testCategory.AddTask(testTask);
            testCategory.Delete();

            List <Category> resultTaskCategories = testTask.GetCategories();
            List <Category> testTaskCategories   = new List <Category> {
            };

            //Assert
            Assert.Equal(testTaskCategories, resultTaskCategories);
        }
        public void Delete_DeletesCategoryFromDatabase_CategoryList()
        {
            //Arrange
            string   name1         = "Home stuff";
            Category testCategory1 = new Category(name1);

            testCategory1.Save();

            string   name2         = "Work stuff";
            Category testCategory2 = new Category(name2);

            testCategory2.Save();

            //Act
            testCategory1.Delete();
            List <Category> resultCategories = Category.GetAll();
            List <Category> testCategoryList = new List <Category> {
                testCategory2
            };

            //Assert
            Assert.Equal(testCategoryList, resultCategories);
        }
Ejemplo n.º 13
0
        public void Test_Delete_DeletesTaskAssociationsFromDatabase()
        {
            //Arrange
            Category testCategory = new Category("Home stuff");

            testCategory.Save();

            string testDescription = "Mow the lawn";
            Task   testTask        = new Task(testDescription, "01-02-2017", false);

            testTask.Save();

            //Act
            testTask.AddCategory(testCategory);
            testTask.Delete();

            List <Task> resultCategoryTasks = testCategory.GetTasks();
            List <Task> testCategoryTasks   = new List <Task> {
            };

            //Assert
            Assert.Equal(testCategoryTasks, resultCategoryTasks);
        }
Ejemplo n.º 14
0
        public void Delete_DeletesTaskAssociationsFromDatabase_TaskList()
        {
            //Arrange
            Category testCategory = new Category("Home stuff");

            testCategory.Save();

            string testDescription = "Mow the lawn";
            bool   testCompletion  = true;
            Task   testTask        = new Task(testDescription, testCompletion);

            testTask.Save();

            //Act
            testTask.AddCategory(testCategory);
            testTask.Delete();

            List <Task> resultCategoryTasks = testCategory.GetTasks();
            List <Task> testCategoryTasks   = new List <Task> {
            };

            //Assert
            Assert.Equal(testCategoryTasks, resultCategoryTasks);
        }
Ejemplo n.º 15
0
        public void Test_Delete_DeletesCategoryFromDatabase()
        {
            //Arrange
            string   name1         = "Home stuff";
            Category testCategory1 = new Category(name1);

            testCategory1.Save();

            string   name2         = "Work stuff";
            Category testCategory2 = new Category(name2);

            testCategory2.Save();

            Task testTask1 = new Task("Mow the lawn", testCategory1.GetId());

            testTask1.Save();
            Task testTask2 = new Task("Send emails", testCategory2.GetId());

            testTask2.Save();

            //Act
            testCategory1.Delete();
            List <Category> resultCategories = Category.GetAll();
            List <Category> testCategoryList = new List <Category> {
                testCategory2
            };

            List <Task> resultTasks  = Task.GetAll();
            List <Task> testTaskList = new List <Task> {
                testTask2
            };

            //Assert
            Assert.Equal(testCategoryList, resultCategories);
            Assert.Equal(testTaskList, resultTasks);
        }
Ejemplo n.º 16
0
    public void Test_GetCategories_ReturnsAllTaskCategories()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

      Category testCategory1 = new Category("Home stuff");
      testCategory1.Save();

      Category testCategory2 = new Category("Work stuff");
      testCategory2.Save();

      //Act
      testTask.AddCategory(testCategory1);
      List<Category> result = testTask.GetCategories();
      List<Category> testList = new List<Category> {testCategory1};

      //Assert
      Assert.Equal(testList, result);
    }
        public void T7_Update_UpdatesCategoryInDatabase()
        {
            //Arrange
              string name = "Home Chores";
              Category testCategory = new Category(name);
              testCategory.Save();
              string newName = "Work Chores";

              //Act
              testCategory.Update(newName);

              string result = testCategory.GetName();

              //Assert
              Assert.Equal(newName, result);
        }
        public void Test_GetTasks_ReturnAllCategoryTasks()
        {
            Category testCategory = new Category("Househould chores");
              testCategory.Save();
              DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask1= new Task("Mow the lawn",testTime);
              testTask1.Save();

              Task testTask2 = new Task("Buy plane ticket",testTime);
              testTask2.Save();

              testCategory.AddTask(testTask1);
              List<Task> savedTasks = testCategory.GetTasks();
              List<Task> testList= new List<Task>{testTask1};
              Assert.Equal(testList,savedTasks);
        }
        public void T8_Delete_DeletesCategoryFromDatabase()
        {
            //Arrange
              string name1 = "Home stuff";
              Category testCategory1 = new Category(name1);
              testCategory1.Save();

              string name2 = "Work stuff";
              Category testCategory2 = new Category(name2);
              testCategory2.Save();

              //Act
              testCategory1.Delete();
              List<Category> resultCategories = Category.GetAll();
              List<Category> testCategoryList = new List<Category> {testCategory2};

              //Assert
              Assert.Equal(testCategoryList, resultCategories);
        }
Ejemplo n.º 20
0
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["login.cshtml"]);
     };
     Post["/categories"] = _ => {
         Admin adminTest = new Admin(Request.Form["user-name"], Request.Form["user-password"]);
         bool  isAdmin   = adminTest.CheckPassword();
         if (isAdmin)
         {
             Admin.SetStatus(true);
             return(View["login.cshtml"]);
         }
         return(View["login.cshtml"]);
     };
     Get["/tasks"] = _ => {
         List <Task> AllTasks = Task.GetAll();
         return(View["tasks.cshtml", AllTasks]);
     };
     Get["/categories"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var AllCategories = Category.GetAll();
         model.Add("categories", AllCategories);
         model.Add("accessTrue", Admin.GetStatus());
         return(View["categories.cshtml", model]);
     };
     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-duedate"], Request.Form["category-id"]);
         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>();
         var SelectedCategory = Category.Find(parameters.id);
         var CategoryTasks    = SelectedCategory.GetTasks();
         model.Add("category", SelectedCategory);
         model.Add("tasks", CategoryTasks);
         return(View["category.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"]);
     };
 }
Ejemplo n.º 21
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"]);
     };
 }
Ejemplo n.º 22
0
        public HomeModule()
        {
            //Index
            Get["/"] = _ => {
              List<Category> AllCategories = Category.GetAll();
              return View["index.cshtml", AllCategories];
            };

            //Get: Lists
            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 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 new task
            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"];
            };

            //"Clear All" routes
            Post["/tasks/clear"] = _ => {
              Task.DeleteAll();
              return View["cleared.cshtml"];
            };
            Post["/categories/clear"] = _ => {
              Category.DeleteAll();
              return View["cleared.cshtml"];
            };

            //View specific category
            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];
            };

            //Edit specific category
            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"];
            };

            //Delete specific category
            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"];
            };
        }
Ejemplo n.º 23
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"]);
            };
            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]);
            };
        }
Ejemplo n.º 24
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"] = _ =>
            {
                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"]);
            };
        }
Ejemplo n.º 25
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["category-id"]);
                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>();
                var SelectedCategory = Category.Find(parameters.id);
                var CategoryTasks    = SelectedCategory.GetTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", CategoryTasks);
                return(View["category.cshtml", model]);
            };



            //       Get["/"] = _ => {
            //         return View["index.cshtml"];
            //       };
            //       //Displays the list of the categories (returns the list called instances)
            //       Get["/all_categories"] = _ => {
            //         var allCategories = Category.GetAll();
            //         return View["all_categories.cshtml", allCategories];
            //       };
            //       //When we select "Add a new category" on the index page, open the category form page
            //       Get["/all_categories/new"] = _ => {
            //         return View["category_form.cshtml"];
            //       };
            //       //Takes info from the form and makes it into a new object. Then we get all of the category objects and show them all on the page
            //       Post["/all_categories"] = _ => {
            //         var newCategory = new Category(Request.Form["category-name"]);
            //         var allCategories = Category.GetAll();
            //         return View["all_categories.cshtml", allCategories];
            //       };
            //       //List of all of the tasks in a single category
            //       //Creates a dictionary with the key as either a 'categry' or a 'task', and the value as the applicable value and task
            //       Get["/all_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];
            //       };
            //       //Adding a task to a selected category
            //       //Displays the form to add a task to that category
            //       Get["/all_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];
            //       };
            //       //list of all the tasks in a single category
            //       Post["/tasks"] = _ => {
            //         Dictionary<string, object> model = new Dictionary<string, object>();
            //         Category selectedCategory = Category.Find(Request.Form["category-id"]);//strongly typed
            //         List<Task> categoryTasks = selectedCategory.GetTasks();// strongly typed. Both are just a different way to type var SelecteCategory etc from previous Get method.
            //         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];
            //       };
            //
        }
Ejemplo n.º 26
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"] = _ => {
                int      year    = Request.Form["year"];
                int      month   = Request.Form["month"];
                int      day     = Request.Form["day"];
                DateTime newDate = new DateTime(year, month, day);

                Task newTask = new Task(Request.Form["task-description"]);
                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>();
                var SelectedCategory = Category.Find(parameters.id);
                var CategoryTasks    = SelectedCategory.GetTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", CategoryTasks);
                return(View["category.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"]);
            };
        }
Ejemplo n.º 27
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]);
            };
        }
Ejemplo n.º 28
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];
              };

              //Create a new task
              Get["/tasks/new"] = _ => {
            return View["tasks_form.cshtml"];
              };
              Post["/tasks/new"] = _ => {
            DateTime newDateTime = Convert.ToDateTime((string)Request.Form["task-date"]);
            Task newTask = new Task(Request.Form["task-description"],newDateTime);
            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["/categories/delete/{id}"] = parameters => {
            Category newCategory = Category.Find(parameters.id);
            newCategory.Delete();
            List<Category> AllCategories = Category.GetAll();
            return View["categories.cshtml",AllCategories];
              };
              //Creates individual pages for category and task
              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["tasks/{id}"] = parameters => {
            Dictionary<string, object> model = new Dictionary<string, object>();
            Task SelectedTask = Task.Find(parameters.id);
            SelectedTask.Update(Request.Form["description"],(bool)Request.Form["task-done"]);
            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["/tasks/delete/{id}"] = parameters => {
            Task newTask = Task.Find(parameters.id);
            newTask.Delete();
            List<Task> AllTasks = Task.GetAll();
            return View["tasks.cshtml", AllTasks];
              };

              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 routes for forms
              Post["task/add_category"] = _ => {
            Category category = Category.Find(Request.Form["category-id"]);
            Task task = Task.Find(Request.Form["task-id"]);
            task.AddCategory(category);
            bool retBool = (bool)Request.Form["task-done"];
            task.SetCompleted(retBool);
            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"];
              };
        }
Ejemplo n.º 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"]);
            };
        }
Ejemplo n.º 30
0
        public HomeModule()
        {
            Get["/"] = _ => {
              return View["index.cshtml"];
            };
            Get["/due-date"] = _ => {
              return View["dueDate_form.cshtml"];
            };

            Get["/duedate"] = _ => {
              List<Task> AllTasks = Task.FindDueDate(Request.Query["latest-date"]);
              return View["tasks.cshtml",AllTasks];
            };

            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["category-id"], Request.Form["new-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>();
              var SelectedCategory = Category.Find(parameters.id);
              var CategoryTasks = SelectedCategory.GetTasks();
              model.Add("category", SelectedCategory);
              model.Add("tasks", CategoryTasks);
              return View["category.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 SelectCategory = Category.Find(parameters.id);
              SelectCategory.Delete();
              return View["success.cshtml"];
            };
        }
Ejemplo n.º 31
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
        }
        public HomeModule()
        {
            //Index
            Get["/"] = _ => {
              return View["index.cshtml"];
            };

            //Get lists
            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"]);
              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"];
            };

            //View individual task/category pages
            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];
            };

            //Add category to task
            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"];
            };

        }
Ejemplo n.º 33
0
        public HomeModule()
        {
            Get["/"] = _ => {
            List<Category> categoryList = Category.GetAll();
            return View["index.cshtml", categoryList];
              };

              Delete["/"]=_=>{
            Category.DeleteAll();
            Task.DeleteAll();
            List<Category> categoryList = Category.GetAll();
            return View["index.cshtml", categoryList];
              };

              Get["/category/add"] = _ => View["add_category.cshtml"];

              Post["/category/add"] = _ => {
            Category newCategory = new Category(Request.Form["name"]);
            newCategory.Save();
            List<Category> categoryList = Category.GetAll();
            return View["index.cshtml", categoryList];
              };

              Get["/task/add"] = _ => {
            List<Category> categoryList = Category.GetAll();
            return View["add_task.cshtml", categoryList];
              };

              Post["/task/add"] = _ => {
            Task newTask = new Task(Request.Form["description"], Request.Form["date"]);
            newTask.Save();
            List<Category> categoryList = Category.GetAll();
            return View["index.cshtml", categoryList];
              };

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

              Get["/category/{id}"] = parameters => {
            Category currentCategory = Category.Find(parameters.id);
            Console.WriteLine(currentCategory.GetName());
            List<Task> tasksInCategory = currentCategory.GetTasks();
            Console.WriteLine(tasksInCategory.Count);
            return View["task_list.cshtml", tasksInCategory];
              };

              Get["task/{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["category/{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);
            Dictionary<string, object> model = new Dictionary<string, object>();
            model.Add("task", task);
            model.Add("taskCategories", task.GetCategories());
            model.Add("allCategories", Category.GetAll());
            return View["task.cshtml", model];
              };

              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> model = new Dictionary<string, object>();
            model.Add("category", category);
            model.Add("categoryTasks", category.GetTasks());
            model.Add("allTasks", Task.GetAll());
            return View["category.cshtml", model];
              };

              Delete["category/{id}/delete"] = parameters =>
              {
            Category category = Category.Find(parameters.id);
            category.Delete();
            List<Category> categoryList = Category.GetAll();
            return View["index.cshtml", categoryList];
              };

              Delete["task/{id}/delete"] = parameters =>
              {
            Task task = Task.Find(parameters.id);
            task.Delete();
            List<Category> categoryList = Category.GetAll();
            return View["index.cshtml", categoryList];
              };

              Patch["task/{id}/complete"] = parameters =>
              {
            Task task = Task.Find(parameters.id);
            task.Complete();
            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);
            return View["task.cshtml", model];
              };
        }
Ejemplo n.º 34
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["/tasks/sort"] = _ => {
                // List<Task> AllTasks = Task.GetAll();
                List <Task> AllSortedTasks = Task.GetSortedList();
                return(View["tasks.cshtml", AllSortedTasks]);
            };

            Post["/categories/{id}/tasks/sort"] = parameters => {
                Dictionary <string, object> model  = new Dictionary <string, object>();
                var         SelectedCategory       = Category.Find(parameters.id);
                List <Task> AllSortedCategoryTasks = SelectedCategory.GetSortedCategoryTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", AllSortedCategoryTasks);
                return(View["category.cshtml", model]);
            };

            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["category-id"], Request.Form["task-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>();
                var SelectedCategory = Category.Find(parameters.id);
                var CategoryTasks    = SelectedCategory.GetTasks();
                model.Add("category", SelectedCategory);
                model.Add("tasks", CategoryTasks);
                return(View["category.cshtml", model]);
            };
        }
Ejemplo n.º 35
0
        public void Test_GetTasks_RetrievesAllTaskWithCategory()
        {
            Category testCategory = new Category("Household chores");
              testCategory.Save();

              DateTime fakeTime = new DateTime(2014, 1, 1);
              Task firstTask = new Task ("Mow the lawn", testCategory.GetId(), fakeTime);
              firstTask.Save();
              Task secondTask = new Task("Do the dishes", testCategory.GetId(), fakeTime);
              secondTask.Save();

              List<Task> testTaskList = new List<Task> {firstTask, secondTask};
              List<Task> resultTaskList = testCategory.GetTasks();

              Assert.Equal(testTaskList, resultTaskList);
        }
Ejemplo n.º 36
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"] = _ => {
            return View["tasks_form.cshtml"];
              };
              Post["/tasks/new"] = _ => {
            Task newTask = new Task(Request.Form["task-description"],Request.Form["task-dueDate"]);
            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>();
            var SelectedCategory = Category.Find(parameters.id);
            var CategoryTasks = SelectedCategory.GetTasks();
            model.Add("category", SelectedCategory);
            model.Add("tasks", CategoryTasks);
            return View["category.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"];
              };

              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"];
              };
        }
Ejemplo n.º 37
0
        public void Test_GetTasks_ReturnsAllCategoryTasks()
        {
            //Arrange
              Category testCategory = new Category("Household chores");
              testCategory.Save();

              Task testTask1 = new Task("Mow the lawn", false);
              testTask1.Save();

              Task testTask2 = new Task("Buy plane ticket", false);
              testTask2.Save();

              //Act
              testCategory.AddTask(testTask1);
              List<Task> savedTasks = testCategory.GetTasks();
              List<Task> testList = new List<Task> {testTask1};

              //Assert
              Assert.Equal(testList, savedTasks);
        }
        public void Test_Delete_DeletesCategoryAssociationsFromDatabase()
        {
            //Arrange
              DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask = new Task("Mow the lawn",testTime);
              testTask.Save();

              string testName = "Home stuff";
              Category testCategory = new Category(testName);
              testCategory.Save();

              //Act
              testCategory.AddTask(testTask);
              testCategory.Delete();

              List<Category> resultTaskCategories = testTask.GetCategories();
              List<Category> testTaskCategories = new List<Category> {};
              List<Task> resultsTasks= Task.GetAll();
              List<Task> testTasks= new List<Task>{testTask};

              //Assert
              Assert.Equal(testTaskCategories, resultTaskCategories);
              Assert.Equal(testTasks, resultsTasks);
        }
Ejemplo n.º 39
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];
            // };
        }
        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];
            // };
        }
Ejemplo n.º 41
0
        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"]);
            };
        }
Ejemplo n.º 42
0
    public void Test_Delete_DeletesTaskFromDatabase()
    {
      //Arrange
      Category testCategory = new Category("Home stuff");
      testCategory.Save();

      string description1 = "Mow the lawn";
      Task testTask1 = new Task(description1);
      testTask1.Save();

      string description2 = "Do homework";
      Task testTask2 = new Task(description2);
      testTask2.Save();

      //Act
      testTask1.AddCategory(testCategory);
      testTask1.Delete();

      List<Task> resultTasks = Task.GetAll();
      List<Task> testTaskList = new List<Task> {testTask2};

      List<Task> resultCategoryTasks = testCategory.GetTasks();
      List<Task> testCategoryTasks = new List<Task> {};

      //Assert
      Assert.Equal(testTaskList, resultTasks);
      Assert.Equal(testCategoryTasks, resultCategoryTasks);
    }
Ejemplo n.º 43
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"], 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];
            };
        }
Ejemplo n.º 44
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]);
            };
        }
Ejemplo n.º 45
0
        public HomeModule()
        {
            //Index
            Get["/"] = _ => {
                List <Category> AllCategories = Category.GetAll();
                return(View["index.cshtml", AllCategories]);
            };

            //Get: Lists
            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 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 new task
            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"]);
            };

            //"Clear All" routes
            Post["/tasks/clear"] = _ => {
                Task.DeleteAll();
                return(View["cleared.cshtml"]);
            };
            Post["/categories/clear"] = _ => {
                Category.DeleteAll();
                return(View["cleared.cshtml"]);
            };

            //View specific category
            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]);
            };

            //Edit specific category
            Get["category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                return(View["category_edit.cshtml", SelectedCategory]);
            };
            Post["category/edit/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.Update(Request.Form["category-name"]);
                return(View["success.cshtml"]);
            };

            //Delete specific category
            Get["category/delete/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                return(View["category_delete.cshtml", SelectedCategory]);
            };
            Post["category/delete/{id}"] = parameters => {
                Category SelectedCategory = Category.Find(parameters.id);
                SelectedCategory.Delete();
                return(View["success.cshtml"]);
            };
        }