public HomeModule() { Get["/"] = _ => View["add_new_task.cshtml"]; Get["/view_all_tasks"] = _ => { List <string> allTasks = Task.GetAll(); //2.instead of Task newTask = new Task(Request.Query["new-task"]); replaced in with List<string> return(View["view_all_tasks.cshtml", allTasks]); //3.view_all_tasks, Nancy will show view_all_tasks.cshtml, with allTasks (which is the result of Task.GetAll(), or _instances) as the Model. //now we need to create ul>f@foreach(string task in Model) at all_tasks.cshtml //then add button set to tasks_cleared to clear out the task. //4. this button, the form submits a post request to the URL /tasks_cleared. Let’s create that route next. //after Post /task_added }; Post["/task_added"] = _ => { Task newTask = new Task(Request.Form["new-task"]); newTask.Save(); return(View["task_added.cshtml", newTask]); //1.added a new route with Post instead of Get. We still instantiate a new Task Obj named newTask //w/Post request, the description is not coming fr the pages'query parameters, //it's coming from the form. So we use Request.Form["new-task"] instead of Request.Query //Then we call save() method on newTask //The request will return the View task_added.cshtml. THis is just going to be a page that display // the Task we just added, newTask, so all we need to do is pass in newTask. //in order for form to follow this route upon being submitted, we need to change the form in add_new_task.cshtml //by changing form action to task_added and add method ="post" now we need to create views/task_added.cshtml //this is where we will add @Model.GetDescription() and link to view-all-tasks }; Post["/tasks_cleared"] = _ => { Task.ClearAll(); return(View["tasks_cleared.cshtml"]); //5.now need to add view/tasks_cleared.cshtml then add method to Objects/Task.cs //when the ClearAll() method in task.cs is call on _instances, setting it back to an empty list. }; }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; Get["/tasks"] = _ => { List <Task> allTasks = Task.GetAll(); return(View["tasks.cshtml", allTasks]); }; Get["/tasks/new"] = _ => { return(View["task_form.cshtml"]); }; Get["/tasks/{id}"] = parameters => { Task task = Task.Find(parameters.id); return(View["/task.cshtml", task]); }; Post["/tasks"] = _ => { Task newTask = new Task(Request.Form["new-task"]); List <Task> allTasks = Task.GetAll(); return(View["tasks.cshtml", allTasks]); }; Post["/clear"] = _ => { List <Task> allTasks = Task.GetAll(); Task.ClearAll(); return(View["tasks.cshtml", allTasks]); }; }
public HomeModule() { Get["/"] = _ => View["add_new_task.cshtml"]; Get["/view_all_tasks"] = _ => { List <string> allTasks = Task.GetAll(); return(View["view_all_tasks.cshtml", allTasks]); }; Post["/task_added"] = _ => { Task newTask = new Task(Request.Form["new-task"]); newTask.Save(); return(View["task_added.cshtml", newTask]); }; Post["/tasks_cleared"] = _ => { Task.ClearAll(); return(View["tasks_cleared.cshtml"]); }; }
public HomeModule() { Get["/"] = _ => View["add_new_task.cshtml"]; Get["/view_all_tasks"] = _ => { List <Task> allTasks = Task.GetAll(); return(View["view_all_tasks.cshtml", allTasks]); }; Post["/task_added"] = _ => { Task newTask = new Task(Request.Form["new-task"]); return(View["task_added.cshtml", newTask]); }; Get["/tasks_cleared"] = _ => { Task.ClearAll(); return(View["tasks_cleared.cshtml"]); }; Get["/tasks/{id}"] = parameters => { Task task = Task.Find(parameters.id); return(View["/task.cshtml", task]); }; }
public HomeModule() { Get["/"] = _ => View["index.cshtml"]; Get["/tasks"] = _ => { List <Task> allTasks = Task.GetAll(); return(View["tasks.cshtml", allTasks]); }; Get["/tasks/new"] = _ => { return(View["task_form.cshtml"]); }; Get["/task/{id}"] = parameters => { Task task = Task.Find(parameters.id); return(View["/task.cshtml", task]); }; Post["/tasks_cleared"] = _ => { Task.ClearAll(); return(View["tasks_cleared.cshtml"]); }; Get["/categories"] = _ => { var allCategories = Category.GetAll(); return(View["categories.cshtml", allCategories]); }; Get["/categories/new"] = _ => { return(View["category_form.cshtml"]); }; Post["/categories"] = _ => { var newCategory = new Category(Request.Form["category-name"]); var allCategories = Category.GetAll(); return(View["categories.cshtml", allCategories]); }; Get["/categories/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedCategory = Category.Find(parameters.id); List <Task> categoryTasks = selectedCategory.GetTasks(); model.Add("category", selectedCategory); model.Add("tasks", categoryTasks); return(View["category.cshtml", model]); }; Get["/categories/{id}/tasks/new"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); Category selectedCategory = Category.Find(parameters.id); List <Task> allTasks = selectedCategory.GetTasks(); model.Add("category", selectedCategory); model.Add("tasks", allTasks); return(View["category_tasks_form.cshtml", model]); }; Post["/tasks"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); Category selectedCategory = Category.Find(Request.Form["category-id"]); List <Task> categoryTasks = selectedCategory.GetTasks(); string taskDescription = Request.Form["task-description"]; Task newTask = new Task(taskDescription); categoryTasks.Add(newTask); model.Add("tasks", categoryTasks); model.Add("category", selectedCategory); return(View["category.cshtml", model]); }; }
public void Dispose() { Task.ClearAll(); }