Esempio n. 1
0
        public ActionResult Post([FromBody] User user)
        {
            try
            {
                context.User.Add(user);
                context.SaveChanges();

                if (user.Role.ToString() != "ADMIN")
                {
                    var userEmailName     = configuration.GetSection("EmailSenderData").GetValue <string>("EmailUserName");
                    var userEmailPassword = configuration.GetSection("EmailSenderData").GetValue <string>("EmailPassword");
                    var smtpClient        = configuration.GetSection("EmailSenderData").GetValue <string>("SMTPClient");
                    var port = configuration.GetSection("EmailSenderData").GetValue <int>("Port");

                    //Code to implement PDF Attachment in Email
                    //Document document = new Document();
                    //document.PdfFormat = PdfFormat.Linearized;
                    //Page page = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
                    //document.Pages.Add(page);

                    //string labelText = "Hello World...\nFrom DynamicPDF Generator for .NET\nDynamicPDF.com HOLA!!!";
                    //Label label = new Label(labelText, 0, 0, 504, 100, Font.Helvetica, 18, TextAlign.Center);
                    //page.Elements.Add(label);
                    //document.Title = "TEST FILE";
                    //byte[] doc = document.Draw();

                    EmailSender.SendEmail(EmailTemplates.GetRegistrationEmailBody(user.UserName, user.Name, user.Surname, user.Email, user.Password),
                                          "Registración Exitosa", user.Email, smtpClient, userEmailName, userEmailPassword, port);
                }

                return(Ok("Registración Exitosa"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }