public static HomeViewModel PrepareHomeViewModel(int userId) { using (var db = new ScrumApplicationDbContext()) { var existUser = db.Users.FirstOrDefault(x => x.UserId == userId); var userTeams = TeamRepository.GetTeams(userId); var homeVM = new HomeViewModel { UserId = userId, UserName = existUser.Name, UserTeams = userTeams, UserActiveProjects = new List <HomeProjectViewModel>() }; foreach (var team in userTeams) { var teamProjects = GetProjects(team.TeamId); foreach (var project in teamProjects) { if (!project.IsDone) { var memberId = TeamRepository.GetUserMemberIdFromProjectId(project.ProjectId); var member = db.Members.FirstOrDefault(x => x.MemberId == memberId); var homeProjectVM = new HomeProjectViewModel { ProjectId = project.ProjectId, ProjectName = project.Name, TeamId = project.TeamId ?? default(int), TeamName = team.Name, MemberId = memberId, RoleCode = member.RoleCode, AssignedActiveBacklogs = new List <ProductBacklog>() }; var projectBacklogs = GetProjectBacklogs(project.ProjectId); foreach (var backlog in projectBacklogs) { if (!backlog.Done && IsUserAssigned(backlog.ProductBacklogId, memberId) == 1 && backlog.SprintNo == project.CurrentSprintNo) { var btm = db.BacklogToMembers.FirstOrDefault (x => x.MemberId == memberId && x.ProductBacklogId == backlog.ProductBacklogId); if (btm != null) { homeProjectVM.AssignedActiveBacklogs.Add(backlog); } } } if (homeProjectVM != null) { homeProjectVM.AssignedActiveBacklogs = homeProjectVM.AssignedActiveBacklogs.OrderBy(x => x.Priority).ToList(); homeVM.UserActiveProjects.Add(homeProjectVM); } } } } return(homeVM); } }
public static List <Project> GetUserProjects(int userId) { using (var db = new ScrumApplicationDbContext()) { var userTeams = TeamRepository.GetTeams(userId); var userProjects = new List <Project>(); foreach (var team in userTeams) { foreach (var project in db.Projects) { if (project.TeamId == team.TeamId && project.IsDone == false) { userProjects.Add(project); } } } return(userProjects); } }