public IActionResult Index(string msgToastr) { // The user has clicked the Cancel, Delete or Save button. // (a) The user has clicked the Cancel button in the Task form. // (b) The user has clicked the Delete button to delete a task. // (c) The user has either created a new task or edited an existing task // and clicked the Save button. We have already saved the task. // We need to display the Welcome page that shows all of the tasks // for THIS project. TempData contains the project Id. // The Save, Delete and Cancel actions REDIRECT to Index(). var projectId = (int)TempData["projectId"]; var project = _context.Projects.SingleOrDefault(p => p.Id == projectId); if (project != null) // user has some projects. { // var tasks = _context.ProjectTasks.Where(t => t.ProjectId == projectId).ToList(); // _context.ProjectTasks.Include(t => t.Priority) // .Where(t => t.ProjectId == projectId).ToList(); var vm = new WelcomeTasksViewModel() { project = project, tasks = tasks, priorities = _context.Priorities.ToList(), nametask = msgToastr }; return(View("Welcome", vm)); } else { return(View("Error")); // User has no projects. This should never happen. } }
public IActionResult TaskListForProject(int pId) { // The user clicked one of the Tasks buttons in the list of projects. // The Id of the project is passed in as pId. How? // It is a form with method post. var project = _context.Projects.SingleOrDefault(p => p.Id == pId); if (project != null) // user has some projects. { var tasks = _context.ProjectTasks.Where(t => t.ProjectId == pId).ToList(); var vm = new WelcomeTasksViewModel() { project = project, tasks = tasks, priorities = _context.Priorities.ToList(), nametask = "" }; return(View("Welcome", vm)); } else { return(View("Error")); } }