/// <summary> /// Handle load index page /// </summary> /// <returns></returns> public async Task <IActionResult> OnGetAsync() { var catIdStr = Request.Query["id"]; var id = ParseTodoCatId(catIdStr); this.TodoCats = await _todoCatServices.GetTodoCategoryListAsync(); // The the first item on the list if (id == 0 && this.TodoCats.Count > 0) { this.ID = this.TodoCats[1].ID; } else if (id > 0) { var curCat = _todoCatServices.FindById(id); if (curCat == null) { return(RedirectToPage("./Error")); } this.ID = curCat.ID; } else if (this.TodoCats.Count == 0) { return(RedirectToPage("./Error")); } return(Page()); }
public async Task <IViewComponentResult> InvokeAsync(int selectedCatId) { var todoList = await _todoListServices.GetTodoListAsync(selectedCatId); var todoCat = _todoCatServices.FindById(selectedCatId); var todoCatName = ""; var remainingTasks = 0; if (todoCat != null) { todoCatName = todoCat.Name; } if (todoList != null & todoList.Count > 0) { remainingTasks = todoList.Count;; foreach (var item in todoList) { if (item.Complete) { remainingTasks--; } } } return(View(new TodoListViewModel { TodoCatId = selectedCatId, TodoCatName = todoCatName, TodoList = todoList, RemainingTasks = remainingTasks })); }