示例#1
0
        public async Task ValidateBuildOnStepFromCoach(string currentUserId, string projectId, string buildOnStepId)
        {
            var project = await _projectsService.GetProjectFromIdAsync(projectId);

            if (project == null)
            {
                throw new Exception("The project doesn't exist");
            }

            Coach coach = await _coachsService.GetCoachFromAdminAsync(currentUserId);

            if (coach == null)
            {
                throw new UnauthorizedAccessException("You are not a coach");
            }

            Coach builderCoach = await _buildersService.GetCoachForBuilderFromAdminAsync(project.BuilderId);

            if (coach.Id != builderCoach?.Id)
            {
                throw new UnauthorizedAccessException("You are not the coach of the builder you wan't to validate step");
            }

            BuildOnReturning returning = new BuildOnReturning()
            {
                ProjectId     = projectId,
                BuildOnStepId = buildOnStepId,
                Type          = BuildOnReturningType.Comment,
                Status        = BuildOnReturningStatus.WaitingAdmin,
                Comment       = "Cette étape a été validé sans preuve"
            };

            await _buildOnReturnings.InsertOneAsync(returning);
        }
示例#2
0
        // Validating step
        public async Task ValidateBuildOnStepFromAdmin(string projectId, string buildOnStepId)
        {
            var project = await _projectsService.GetProjectFromIdAsync(projectId);

            if (project == null)
            {
                throw new Exception("The project doesn't exist");
            }

            BuildOnReturning returning = new BuildOnReturning()
            {
                ProjectId     = projectId,
                BuildOnStepId = buildOnStepId,
                Type          = BuildOnReturningType.Comment,
                Status        = BuildOnReturningStatus.WaitingCoach,
                Comment       = "Cette étape a été validé sans preuve"
            };

            await _buildOnReturnings.InsertOneAsync(returning);
        }
示例#3
0
        // Sending proof
        public async Task <string> SendReturningAsync(string currentUserId, string projectId, BuildOnReturningSubmitModel buildOnReturningSubmitModel)
        {
            // First we need basics checks
            Builder builder = await _buildersService.GetBuilderFromAdminAsync(currentUserId);

            if (builder == null)
            {
                throw new UnauthorizedAccessException("You are not a builder");
            }

            Coach coachForBuilder = await _buildersService.GetCoachForBuilderFromAdminAsync(builder.Id);

            var project = await _projectsService.GetProjectAsync(builder.Id);

            if (project == null)
            {
                throw new Exception("The project doesn't exist");
            }
            if (coachForBuilder == null)
            {
                throw new Exception("This builder don't have a coach...");
            }
            if (project.Id != projectId)
            {
                throw new UnauthorizedAccessException("The project doesn't belong to you");
            }

            User userForCoach = await _coachsService.GetUserFromAdminAsync(coachForBuilder.Id);

            if (userForCoach == null)
            {
                throw new Exception("The coach doesn't have any user");
            }

            // Then we register the returning
            string fileId = null;

            if (buildOnReturningSubmitModel.File != null && buildOnReturningSubmitModel.File.Length >= 1)
            {
                var filename = $"{projectId}_{buildOnReturningSubmitModel.FileName}";
                fileId = await _filesService.UploadFile(filename, buildOnReturningSubmitModel.File, false);
            }

            BuildOnReturning returning = new BuildOnReturning()
            {
                ProjectId     = projectId,
                BuildOnStepId = buildOnReturningSubmitModel.BuildOnStepId,
                Type          = buildOnReturningSubmitModel.Type,
                Status        = BuildOnReturningStatus.Waiting,
                FileName      = buildOnReturningSubmitModel.FileName,
                FileId        = fileId,
                Comment       = buildOnReturningSubmitModel.Comment
            };

            await _buildOnReturnings.InsertOneAsync(returning);

            // Now we need to notify the coach
            await _notificationService.NotifyBuildOnReturningSubmited(coachForBuilder.Id, userForCoach.Email);

            return(returning.Id);
        }