public IList <SprintM> GetAll(Guid project_id)
        {
            try
            {
                var result = _sprint.Where(s => s.ProjectId.Equals(project_id)).OrderByDescending(s => s.No)
                             .Select(s => new SprintM
                {
                    EndDate   = s.EndDate,
                    Id        = s.Id,
                    No        = s.No,
                    StartDate = s.StartDate,
                    Stage     = new Stage
                    {
                        StageCode = s.StageCode,
                        Name      = s.StageCode.ToString()
                    },
                    NextStage = new Stage
                    {
                        StageCode = StageUtils.GetNextStage(s.StageCode),
                        Name      = StageUtils.GetNextStage(s.StageCode).ToString()
                    }
                }).ToList();

                foreach (var sprint in result)
                {
                    sprint.IsRequireApproval = _approval.Any(a => a.SprintId.Equals(sprint.Id) && a.StageCode.Equals(sprint.NextStage.StageCode));
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred while get all sprint!",
                                                                         e, DateTime.Now, "Server", "Service_Sprint_GetAll");
            }
        }
        public IList <ProjectLastSprintM> GetAll(Guid user_id)
        {
            try
            {
                var result = _permission.Where(p => p.Project.Permissions.Any(p => p.UserId.Equals(user_id)) && p.RoleId.Equals(RoleID.Admin))
                             .Select(p => new ProjectLastSprintM
                {
                    CreatedDate = p.Project.CreatedDate,
                    EndDate     = p.Project.EndDate,
                    Id          = p.Project.Id,
                    Name        = p.Project.Name,
                    ProjectType = new ProjectTypeM
                    {
                        Id   = p.Project.ProjectType.Id,
                        Name = p.Project.ProjectType.Name
                    },
                    StartDate = p.Project.StartDate,
                    Owner     = new UserM
                    {
                        Id       = p.User.Id,
                        Username = p.User.Username
                    },
                    TotalSprint = p.Project.Sprints.Count(),
                    LastSprint  = p.Project.Sprints.OrderByDescending(s => s.No).Select(s => new SprintM
                    {
                        No        = s.No,
                        EndDate   = s.EndDate,
                        Id        = s.Id,
                        NextStage = new Models.Nococid.Stage
                        {
                            Name      = StageUtils.GetNextStage(s.StageCode).ToString(),
                            StageCode = StageUtils.GetNextStage(s.StageCode)
                        },
                        Stage = new Models.Nococid.Stage
                        {
                            StageCode = s.StageCode,
                            Name      = s.StageCode.ToString()
                        },
                        StartDate = s.StartDate
                    }).FirstOrDefault()
                }).ToList();

                foreach (var project in result)
                {
                    if (project.LastSprint != null)
                    {
                        project.LastSprint.IsRequireApproval = _approval.Any(a => a.SprintId.Equals(project.LastSprint.Id) && a.StageCode.Equals(project.LastSprint.NextStage.StageCode));
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred while get all project!",
                                                                         e, DateTime.Now, "Server", "Service_Project_GetAll");
            }
        }
Example #3
0
 public SprintTasksM GetAllMyTask(Guid sprint_id, Guid user_id)
 {
     try
     {
         var result = _sprint.Where(s => s.Id.Equals(sprint_id))
                      .Select(s => new SprintTasksM
         {
             Id        = s.Id,
             NextStage = new Models.Nococid.Stage
             {
                 Name      = StageUtils.GetNextStage(s.StageCode).ToString(),
                 StageCode = StageUtils.GetNextStage(s.StageCode)
             },
             Stage = new Models.Nococid.Stage
             {
                 StageCode = s.StageCode,
                 Name      = s.StageCode.ToString()
             },
             No        = s.No,
             StartDate = s.StartDate,
             EndDate   = s.EndDate,
             Tasks     = s.StageCode.Equals(StageEnum.Planning) == true ? null : s.Tasks.Where(t => t.UserId.Equals(user_id)).Select(t => new TaskDM
             {
                 AssignedUser = new UserM
                 {
                     Id       = t.User.Id,
                     Username = t.User.Username
                 },
                 Id     = t.Id,
                 Detail = t.Detail,
                 Name   = t.Name,
                 Side   = t.Side,
                 Status = t.Status
             }).ToList()
         }).FirstOrDefault();
         if (result != null)
         {
             result.IsRequireApproval = _approval.Any(a => a.SprintId.Equals(result.Id) && a.StageCode.Equals(result.NextStage.StageCode));
         }
         return(result);
     }
     catch (Exception e)
     {
         throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred while get all my tasks!",
                                                                  e, DateTime.Now, "Server", "Service_Task_GetAll");
     }
 }
        public SprintM GoNextStage(Guid project_id, Guid sprint_id)
        {
            try
            {
                Sprint sprint = _sprint.GetOne(s => s.Id.Equals(sprint_id) && s.ProjectId.Equals(project_id));
                if (sprint == null)
                {
                    throw NotFound(sprint_id, "sprint id");
                }
                StageEnum next_stage = StageUtils.GetNextStage(sprint.StageCode);
                if (!_approval.Any(a => a.SprintId.Equals(sprint_id) && a.StageCode.Equals(next_stage)))
                {
                    throw BadRequest("The next stage will be automatically approved. This action should not be performed!");
                }

                sprint.StageCode = next_stage;
                SaveChanges();
                next_stage = StageUtils.GetNextStage(next_stage);

                return(new SprintM
                {
                    EndDate = sprint.EndDate,
                    Id = sprint.Id,
                    No = sprint.No,
                    StartDate = sprint.StartDate,
                    Stage = new Stage
                    {
                        StageCode = sprint.StageCode,
                        Name = sprint.StageCode.ToString()
                    },
                    NextStage = new Stage
                    {
                        StageCode = next_stage,
                        Name = next_stage.ToString()
                    },
                    IsRequireApproval = _approval.Any(a => a.SprintId.Equals(sprint.Id) && a.StageCode.Equals(next_stage))
                });
            }
            catch (Exception e)
            {
                throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred while go to next stage of a sprint!",
                                                                         e, DateTime.Now, "Server", "Service_Sprint_GoNextStage");
            }
        }
 public void GoNextStage(Guid sprint_id)
 {
     try
     {
         Sprint sprint = _sprint.GetOne(s => s.Id.Equals(sprint_id));
         if (sprint == null)
         {
             throw NotFound(sprint_id, "sprint id");
         }
         StageEnum next_stage = StageUtils.GetNextStage(sprint.StageCode);
         if (!_approval.Any(a => a.SprintId.Equals(sprint_id) && a.StageCode.Equals(next_stage)))
         {
             sprint.StageCode = next_stage;
             SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e is RequestException ? e : _errorHandler.WriteLog("An error occurred while go to next stage of a sprint!",
                                                                  e, DateTime.Now, "Server", "Service_Sprint_GoNextStage");
     }
 }