public bool StartMonitoring_SprintIndexViewModel(SprintIndexViewModel model) { //Find the user's Id string userId = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId(); //Add this user as watching for Colleague Adds Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(userId)); //Add this user as watching updates on each colleague Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(ViewModelDataType.Sprint, ActionType.Index, sId: userId)); foreach (var proj in model.Projects) { Groups.Add(Context.ConnectionId, LiveUpdateHelper.GroupName(ViewModelDataType.Sprint, ActionType.Details, proj.ProjectId)); } //TODO: check if the model has changed, god knows how to do this when it's so big... return(true); }
// GET: Sprint public async Task <ActionResult> Index(/* int? id */) { //Find user var currentUser = await _userManager.FindByIdAsync(User.Identity.GetUserId()); if (currentUser == null) { return(RedirectToAction("LogOff", "Account")); //If the user is here without a found user then it must be an old cookie } //Generate model var model = new SprintIndexViewModel() { UserName = currentUser.Fullname ?? currentUser.Email, Projects = new List <ProjectSprintViewModel>() }; //Hack in this sprint... //if (id != null) //{ // //Find current sprint // var thisSprint = await _db.Sprints.FindAsync(id); // var thisProjSprint = new ProjectSprintViewModel() // { // ProjectId = thisSprint.Project_Id, // ProjectName = thisSprint.Project.Title, // TeamName = thisSprint.Project.Teams.First().Team.TeamName, // SprintItteration = thisSprint.Iteration, // SprintStartDate = thisSprint.StartDate, // SprintEndDate = thisSprint.EndDate, // Features = new List<SprintFeatures>() // }; // //Add features to view model // foreach (var feat in thisSprint.Features.OrderBy(f => f.Priority)) // { // thisProjSprint.Features.Add(new SprintFeatures() // { // FeatureId = feat.Id, // FeatureName = feat.Title, // FeatureDescription = feat.Description, // TasksNotStarted = feat.Tasks.Where(t => t.State == EnumTaskState.NotStarted).OrderBy(p => p.Priority).Select(t => new TaskItemViewModel(t)).ToList(), // TasksInProgress = feat.Tasks.Where(t => t.State == EnumTaskState.InProgress).OrderBy(p => p.Priority).Select(t => new TaskItemViewModel(t)).ToList(), // TasksDone = feat.Tasks.Where(t => t.State == EnumTaskState.Done).OrderBy(p => p.Priority).Select(t => new TaskItemViewModel(t)).ToList() // }); // } // model.Projects.Add(thisProjSprint); // return View(model); //} //Add projects var teams = currentUser.Teams.Select(member => member.Team); foreach (var team in teams) { foreach (var proj in team.Projects) { //Check we haven't already added this project if (model.Projects.Any(i => i.ProjectId == proj.ProjectId)) { continue; } //Find current sprint var thisSprint = proj.Project.GetThisSprint(); //Skip project if we can't find the current sprint if (thisSprint == null) { continue; } var thisProjSprint = new ProjectSprintViewModel() { ProjectId = proj.ProjectId, ProjectName = proj.Project.Title, TeamName = team.TeamName, SprintItteration = thisSprint.Iteration, SprintStartDate = thisSprint.StartDate, SprintEndDate = thisSprint.EndDate, Features = new List <SprintFeatures>() }; //Add features to view model foreach (var feat in thisSprint.Features.OrderBy(f => f.Priority)) { thisProjSprint.Features.Add(new SprintFeatures() { FeatureId = feat.Id, FeatureName = feat.Title, FeatureDescription = feat.Description, TasksNotStarted = feat.Tasks.Where(t => t.State == EnumTaskState.NotStarted).OrderBy(p => p.Priority).Select(t => new TaskItemViewModel(t)).ToList(), TasksInProgress = feat.Tasks.Where(t => t.State == EnumTaskState.InProgress).OrderBy(p => p.Priority).Select(t => new TaskItemViewModel(t)).ToList(), TasksDone = feat.Tasks.Where(t => t.State == EnumTaskState.Done).OrderBy(p => p.Priority).Select(t => new TaskItemViewModel(t)).ToList() }); } model.Projects.Add(thisProjSprint); } } return(View(model)); }