Пример #1
0
 public static bool CompleteBacklog(int backlogId, int?memberId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var existTask = new ProductBacklog();
         existTask = db.ProductBacklogs.FirstOrDefault(x => x.ProductBacklogId == backlogId);
         if (!memberId.HasValue)
         {
             memberId = TeamRepository.GetUserMemberIdFromProjectId(existTask.ProjectId);
         }
         var existMember = db.Members.FirstOrDefault(x => x.MemberId == memberId);
         if (existMember != null)
         {
             if (ProjectRepository.IsUserAssigned(backlogId, existMember.MemberId) == 1)
             {
                 if (existTask.BacklogStatus < Status.Completed)
                 {
                     existTask.BacklogStatus = Status.Completed;
                 }
                 existTask.Done          = true;
                 existMember.TotalPoint += existTask.StoryPoint;
                 db.SaveChanges();
                 ActivityRepository.ActivityCreator
                     ("completed " + existTask.Name, existTask.ProjectId, existTask.ProductBacklogId);
                 return(true);
             }
         }
         return(false);
     }
 }
Пример #2
0
 //Check is user assigned to selected backlog, return bool
 public static int IsUserAssigned(int backlogId, int?memberId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var existBacklog = db.ProductBacklogs.FirstOrDefault(x => x.ProductBacklogId == backlogId);
         if (!memberId.HasValue)
         {
             memberId = TeamRepository.GetUserMemberIdFromProjectId(existBacklog.ProjectId);
         }
         if (memberId != 0 && existBacklog != null)
         {
             var existBTM = db.BacklogToMembers.FirstOrDefault(x => x.MemberId == memberId && x.ProductBacklogId == backlogId);
             if (existBTM != null)
             {
                 return(1);
             }
             var _existBTM = db.BacklogToMembers.FirstOrDefault(x => x.ProductBacklogId == existBacklog.ProductBacklogId);
             if (_existBTM != null && _existBTM.MemberId != memberId)
             {
                 return(2);
             }
         }
         return(0);
     }
 }
Пример #3
0
 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);
     }
 }
Пример #4
0
 public static void ActivityCreator(string ActivityString, int projectId, int?backlogId)
 {
     using (var db = new ScrumApplicationDbContext())
     {
         var memberId    = TeamRepository.GetUserMemberIdFromProjectId(projectId);
         var existMember = db.Members.FirstOrDefault(x => x.MemberId == memberId);
         var newActivity = new Activity();
         newActivity.MemberId  = memberId;
         newActivity.ProjectId = projectId;
         if (backlogId.HasValue)
         {
             newActivity.BacklogId = backlogId;
         }
         newActivity.ActivityDescription =
             existMember.Name + " " + ActivityString;
         //" at time: " + DateTime.Now.Minute + "." + DateTime.Now.Hour + " - " + DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year
         db.Activities.Add(newActivity);
         db.SaveChanges();
     }
 }