// 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)); }
public void EntityUpdated(projectList updatedEntities) { using (var db = new ApplicationDbContext()) { Trace.WriteLine("Updated Project"); foreach (var tuple in updatedEntities) { switch (tuple.Item1) { case EntityState.Modified: { var dbProject = db.Projects.Find(tuple.Item2.Id); if (dbProject == null) { continue; //Project has been deleted } //Update Project Details box var detailsViewModel = new ProjectDetailsViewModel(dbProject); Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Project, ActionType.Details, dbProject.Id)) .UpdateData(ViewModelDataType.Project.ToString(), ActionType.Details.ToString(), detailsViewModel); //Update Projects List var projectItemViewModel = new ProjectItemViewModel(dbProject); Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Project, ActionType.Index, dbProject.Id)) .UpdateItemData(ViewModelDataType.Project.ToString(), ActionType.Index.ToString(), projectItemViewModel); //Update Sprint Board foreach (var team in dbProject.Teams) { var thisSprint = dbProject.GetThisSprint(); var thisProjSprint = new ProjectSprintViewModel() { ProjectId = dbProject.Id, ProjectName = dbProject.Title, TeamName = team.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() }); } //Push to group Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Sprint, ActionType.Details, dbProject.Id)) .UpdateItemData(ViewModelDataType.Sprint.ToString(), ActionType.Index.ToString(), thisProjSprint); } } break; case EntityState.Added: { //Find owner and push add var dbProject = db.Projects.Find(tuple.Item2.Id); if (dbProject == null) { continue; //Project has been deleted } var projectItemViewModel = new ProjectItemViewModel(dbProject); var group = Clients.Group(LiveUpdateHelper.GroupName(dbProject.User_Id)); group.AddData(ViewModelDataType.Project.ToString(), ActionType.Index.ToString(), projectItemViewModel); } break; case EntityState.Deleted: { //Find owner and push delete if (tuple.Item2 != null) { var group = Clients.Group(LiveUpdateHelper.GroupName(ViewModelDataType.Project, ActionType.Index, tuple.Item2.Id)); group.RemoveData(ViewModelDataType.Project.ToString(), ActionType.Index.ToString(), tuple.Item2.Id); } } break; } } } }