Exemplo n.º 1
0
        public bool SignBuilderIntegration(string builderId, PdfIntegrationBuilder values)
        {
            var filePath = Path.Combine(_env.ContentRootPath, $"PDF/integration_builder_fillable.pdf");
            var savePath = Path.Combine(_env.ContentRootPath, $"wwwroot/pdf/builders/{builderId}.pdf");

            PdfDocument pdf          = new PdfDocument(new PdfReader(filePath), new PdfWriter(savePath));
            PdfAcroForm form         = PdfAcroForm.GetAcroForm(pdf, false);
            PdfFont     documentFont = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);

            var fields = form.GetFormFields();

            foreach (PdfFormField field in fields.Values)
            {
                field.SetFontSize(10);
                field.SetFont(documentFont);
            }

            fields["lastname"].SetValue(values.LastName);
            fields["firstname"].SetValue(values.FirstName);
            fields["birth_place"].SetValue(values.BirthPlace ?? values.City);
            fields["birthdate"].SetValue(string.Format("{0:dd/MM/yyyy}", values.Birthdate));
            fields["email"].SetValue(values.Email);
            fields["mobile"].SetValue(values.Phone);
            fields["linkedin"].SetValue(values.LinkedIn ?? "");
            fields["discord"].SetValue(values.DiscordTag ?? "");
            fields["address"].SetValue(values.Address);
            fields["city"].SetValue(values.City);
            fields["postal_code"].SetValue(values.PostalCode.ToString());
            fields["situation"].SetValue(values.Situation);
            fields["domains"].SetValue(values.ProjectDomaine);
            fields["project_name"].SetValue(values.ProjectName);
            fields["project_launch_date"].SetValue(string.Format("{0:dd/MM/yyyy}", values.ProjectLaunchDate));
            fields["description"].SetValue(values.ProjectDescription);
            fields["team"].SetValue(values.ProjectTeam);
            fields["expectations"].SetValue(values.Expectation ?? "Impossible de récupérer cet information");
            fields["s_fullname"].SetValue($"{values.FirstName} {values.LastName}");
            fields["s_birthdate"].SetValue(string.Format("{0:dd/MM/yyyy}", values.Birthdate));
            fields["s_place_birth"].SetValue(values.BirthPlace);
            fields["s_address"].SetValue($"{values.Address}, {values.PostalCode} {values.City}");
            fields["s_sign_place"].SetValue(values.City);
            fields["s_sign_date"].SetValue(string.Format("{0:dd/MM/yyyy}", DateTime.Now));

            PdfAcroForm.GetAcroForm(pdf, false).FlattenFields();

            pdf.Close();

            return(true);
        }
Exemplo 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);
        }