Esempio n. 1
0
        public async Task <List <AvailableCoachModel> > GetAvailableCoachAsync()
        {
            var activeCoachs = await(await _coachs.FindAsync(databaseCoach =>
                                                             databaseCoach.Status == CoachStatus.Validated
                                                             )).ToListAsync();

            // We need to exclude coach who already have a builder
            var           builders          = await(await _builders.FindAsync(databaseBuilder => true)).ToListAsync();
            List <string> unavailableCoachs = new();

            foreach (Builder builder in builders)
            {
                if (builder.CoachId != null)
                {
                    unavailableCoachs.Add(builder.CoachId);
                }
            }

            List <AvailableCoachModel> availableCoachModels = new();

            foreach (Coach activeCoach in activeCoachs)
            {
                if (unavailableCoachs.Contains(activeCoach.Id))
                {
                    continue;
                }

                User user = await GetUserFromAdminAsync(activeCoach.Id);

                if (user == null)
                {
                    continue;
                }

                AvailableCoachModel model = new AvailableCoachModel()
                {
                    Id = activeCoach.Id,

                    UserId    = user.Id,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,

                    Email      = user.Email,
                    DiscordTag = user.DiscordTag,
                    LinkedIn   = user.LinkedIn,

                    Situation   = activeCoach.Situation,
                    Description = activeCoach.Description,

                    Competences = await _formsService.GetAnswerForQuestionAsync(user.Id, "Quelles sont vos compétences clés ?") ?? "Inconnue",
                    Questions   = new List <string>()
                    {
                        "Comment définis-tu le rôle de Coach ?",
                        "Pourquoi souhaites-tu devenir Coach ?",
                        "Qu’est-ce qui t'incite à proposer ton accompagnement ?",
                        "Combien d’heures par semaine peux-tu accorder à un Builder ?",
                        "Es-tu prêt à faire preuve de patience, d’écoute et de bienveillance à l’égard des Builders ?",
                        "Quel serait le Builder idéal pour toi ?",
                        "C'est ton moment. Dis au Builder pourquoi il doit te choisir te et pas un autre Coach."
                    },

                    Answers = new List <string>()
                    {
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "Comment définis-tu le rôle de Coach ?") ?? "Inconnue",
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "Pourquoi souhaites-tu devenir Coach ?") ?? "Inconnue",
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "Qu’est-ce qui t'incite à proposer ton accompagnement ?") ?? "Inconnue",
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "Combien d’heures par semaine peux-tu accorder à un Builder ?") ?? "Inconnue",
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "Es-tu prêt à faire preuve de patience, d’écoute et de bienveillance à l’égard des Builders ?") ?? "Inconnue",
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "Quel serait le Builder idéal pour toi ?") ?? "Inconnue",
                        await _formsService.GetAnswerForQuestionAsync(user.Id, "C'est ton moment. Dis au Builder pourquoi il doit te choisir toi et pas un autre Coach.") ?? "Inconnue"
                    }
                };

                availableCoachModels.Add(model);
            }

            return(availableCoachModels);
        }
Esempio n. 2
0
        // Signging the PDF for the integration
        public async Task <bool> SignFicheIntegrationAsync(string currentUserId, string builderId)
        {
            Builder builder = await GetBuilderFromBuilderId(builderId);

            if (builder == null)
            {
                throw new Exception("The builder doesn't exist");
            }
            if (builder.UserId != currentUserId)
            {
                throw new UnauthorizedAccessException("You are not the builder you want to sign for");
            }

            User user = await GetUserFromId(builder.UserId);

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

            Project project = await _projectsService.GetProjectAsync(builderId);

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

            PdfIntegrationBuilder pdfIntegrationBuilder = new PdfIntegrationBuilder()
            {
                FirstName  = user.FirstName,
                LastName   = user.LastName,
                Birthdate  = user.Birthdate,
                BirthPlace = user.BirthPlace,

                Email      = user.Email,
                Phone      = user.Phone,
                DiscordTag = user.DiscordTag,
                LinkedIn   = user.LinkedIn,

                City       = user.City,
                PostalCode = user.PostalCode,
                Address    = user.Address,

                Situation = builder.Situation,

                Expectation = await _formsService.GetAnswerForQuestionAsync(currentUserId, "Pourquoi souhaites-tu intégrer le programme Build Up ?"),

                ProjectDomaine     = project.Categorie,
                ProjectName        = project.Name,
                ProjectLaunchDate  = project.LaunchDate,
                ProjectDescription = project.Description,
                ProjectTeam        = project.Team
            };

            if (_pdfService.SignBuilderIntegration(builderId, pdfIntegrationBuilder))
            {
                var update = Builders <Builder> .Update
                             .Set(dbBuilder => dbBuilder.HasSignedFicheIntegration, true);

                var builderCard = _pdfService.GenerateBuilderCard(builderId, new PdfBuilderCard()
                {
                    FirstName    = user.FirstName,
                    LastName     = user.LastName,
                    Birthdate    = user.Birthdate,
                    ValidityDate = builder.CandidatingDate.AddMonths(3)
                });

                var fileId = await _filesService.UploadFile($"buildercard_{builderId}", builderCard);

                update = update.Set(dbBuilder => dbBuilder.BuilderCardId, fileId);

                await _builders.UpdateOneAsync(databaseBuilder =>
                                               databaseBuilder.Id == builderId,
                                               update
                                               );

                await _notificationService.NotifySignedIntegrationPaperBuilder(builderId, user.Email, user.FirstName);

                return(true);
            }

            return(false);
        }