Beispiel #1
0
        public async Task <IActionResult> Register(AddUserViewModel model, IFormFile Image)
        {
            if (!model.termsAccept)
            {
                ModelState.AddModelError(string.Empty, "I must accept the license terms in order to register.");
                return(View(model));
            }
            if (ModelState.IsValid)
            {
                if (Image != null && Image.Length > 0)
                {
                    var _iImageHelper = new ImageHelper();
                    model.Photo     = _iImageHelper.UploadImageDB(Image);
                    model.PhotoPath = await _iImageHelper.UploadImageDirectoryAsync(Image, "Users");
                }
                var user = await AddUserAsync(model);

                if (user == null)
                {
                    //Para Eliminar la foto fisica..
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img\\Users", model.PhotoPath.Substring(12));
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    ModelState.AddModelError(string.Empty, "This email is already used.");
                    return(View(model));
                }

                //var owner = new Owner
                //{
                //    Pets = new List<Pet>(),
                //    User = user,
                //};

                //_dataContext.Owners.Add(owner);
                //await _dataContext.SaveChangesAsync();

                var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user);

                var tokenLink = Url.Action("ConfirmEmail", "Account", new
                {
                    userid = user.Id,
                    token  = myToken
                }, protocol: HttpContext.Request.Scheme);

                _mailHelper.EnviarMail(model.Username, "Email confirmation",
                                       $"<table style = 'max-width: 600px; padding: 10px; margin:0 auto; border-collapse: collapse;'>" +
                                       $"  <tr>" +
                                       $"    <td style = 'background-color: #34495e; text-align: center; padding: 0'>" +
                                       $"       <a href = 'https://www.facebook.com/NuskeCIV/' >" +
                                       $"         <img width = '20%' style = 'display:block; margin: 1.5% 3%' src= 'https://veterinarianuske.com/wp-content/uploads/2016/10/line_separator.png'>" +
                                       $"       </a>" +
                                       $"  </td>" +
                                       $"  </tr>" +
                                       $"  <tr>" +
                                       $"  <td style = 'padding: 0'>" +
                                       $"     <img style = 'padding: 0; display: block' src = 'https://veterinarianuske.com/wp-content/uploads/2018/07/logo-nnske-blanck.jpg' width = '100%'>" +
                                       $"  </td>" +
                                       $"</tr>" +
                                       $"<tr>" +
                                       $" <td style = 'background-color: #ecf0f1'>" +
                                       $"      <div style = 'color: #34495e; margin: 4% 10% 2%; text-align: justify;font-family: sans-serif'>" +
                                       $"            <h1 style = 'color: #e67e22; margin: 0 0 7px' > Hola </h1>" +
                                       $"                    <p style = 'margin: 2px; font-size: 15px'>" +
                                       $"                      El mejor Hospital Veterinario Especializado de la Ciudad de Morelia enfocado a brindar servicios médicos y quirúrgicos<br>" +
                                       $"                      aplicando las técnicas más actuales y equipo de vanguardia para diagnósticos precisos y tratamientos oportunos..<br>" +
                                       $"                      Entre los servicios tenemos:</p>" +
                                       $"      <ul style = 'font-size: 15px;  margin: 10px 0'>" +
                                       $"        <li> Urgencias.</li>" +
                                       $"        <li> Medicina Interna.</li>" +
                                       $"        <li> Imagenologia.</li>" +
                                       $"        <li> Pruebas de laboratorio y gabinete.</li>" +
                                       $"        <li> Estetica canina.</li>" +
                                       $"      </ul>" +
                                       $"  <div style = 'width: 100%;margin:20px 0; display: inline-block;text-align: center'>" +
                                       $"    <img style = 'padding: 0; width: 200px; margin: 5px' src = 'https://veterinarianuske.com/wp-content/uploads/2018/07/tarjetas.png'>" +
                                       $"  </div>" +
                                       $"  <div style = 'width: 100%; text-align: center'>" +
                                       $"    <h2 style = 'color: #e67e22; margin: 0 0 7px' >Email Confirmation </h2>" +
                                       $"    To allow the user,plase click in this link:</ br ></ br > " +
                                       $"    <a style ='text-decoration: none; border-radius: 5px; padding: 11px 23px; color: white; background-color: #3498db' href = \"{tokenLink}\">Confirm Email</a>" +
                                       $"    <p style = 'color: #b3b3b3; font-size: 12px; text-align: center;margin: 30px 0 0' > Nuskë Clinica Integral Veterinaria 2019 </p>" +
                                       $"  </div>" +
                                       $" </td >" +
                                       $"</tr>" +
                                       $"</table>");
                ViewBag.Message = "The instructions to allow your user has been sent to email.";
                return(View(model));
            }

            return(View(model));
        }