Esempio n. 1
0
        public async Task <IActionResult> Contacts(ContactFormInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            Gmailer.GmailUsername = "******";
            Gmailer.GmailPassword = "******";
            Gmailer mailer = new Gmailer();

            mailer.ToEmail = "*****@*****.**";
            mailer.Subject = model.Subject;
            mailer.Body    = $"Hello InteriorDesign.com owner,\n\r" +
                             $"This is a new contact request from your website:\n\r" +
                             $"Full Name: {model.Name}\n\r" +
                             $"Email: {model.Email}\n\r" +
                             $"Message: {model.Message}\n\r" +
                             "Cheers,\n\rThe InteriorDesign contact form";

            mailer.IsHtml = true;
            mailer.Send();

            return(this.Redirect("Index"));
        }
        public async Task CreateMethodShouldAddCorrectNewContactFormToDb()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new ApplicationDbContext(optionsBuilder.Options);

            var contactsService = new ContactsService(dbContext);

            var contactFormToAdd = new ContactFormInputModel
            {
                Name    = "testName",
                Content = "testContent",
                Email   = "testEmail",
                Title   = "testTitle",
            };

            await contactsService.CreateAsync(contactFormToAdd, "ip");

            Assert.NotNull(dbContext.ContactForms.FirstOrDefaultAsync());
            Assert.Equal("testName", dbContext.ContactForms.FirstAsync().Result.Name);
            Assert.Equal("testContent", dbContext.ContactForms.FirstAsync().Result.Content);
            Assert.Equal("testEmail", dbContext.ContactForms.FirstAsync().Result.Email);
            Assert.Equal("testTitle", dbContext.ContactForms.FirstAsync().Result.Title);
            Assert.Equal("ip", dbContext.ContactForms.FirstAsync().Result.Ip);
        }
Esempio n. 3
0
        public async Task SendEmailToAdminAsync(ContactFormInputModel inputModel)
        {
            if (this.contactsRepository.All()
                .Any(
                    x => x.Name == inputModel.Name &&
                    x.Email == inputModel.Email &&
                    x.Title == inputModel.Title &&
                    x.Message == inputModel.Message))
            {
                throw new ArgumentException(ExceptionMessages.ContactFormAlreadyExists);
            }

            var contactForm = new ContactForm
            {
                Name    = inputModel.Name,
                Email   = inputModel.Email,
                Title   = inputModel.Title,
                Message = inputModel.Message,
            };

            await this.contactsRepository.AddAsync(contactForm);

            await this.contactsRepository.SaveChangesAsync();

            await this.emailSender.SendEmailAsync(
                contactForm.Email,
                contactForm.Name,
                GlobalConstants.AdinistratorEmail,
                contactForm.Title,
                contactForm.Message);
        }
        protected async Task HandleValidSubmit()
        {
            var contactInfo = new ContactFormInputModel()
            {
                Name    = _contactFormInput.Name,
                Subject = _contactFormInput.Subject,
                Email   = _contactFormInput.Email,
                Message = _contactFormInput.Message
            };

            SubmitState = SubmitStateEnum.Sending;

            StateHasChanged();

            try
            {
                await HttpClient.PostJsonAsync("api/message", contactInfo);

                SubmitState = SubmitStateEnum.Success;

                StateHasChanged();
            }
            catch (Exception e)
            {
                SubmitState = SubmitStateEnum.Failed;

                StateHasChanged();
                throw;
            }
        }
        public async Task <int> Create(ContactFormInputModel input)
        {
            var contactForm = AutoMapperConfig.MapperInstance.Map <ContactForm>(input);
            await contactFormsRepository.AddAsync(contactForm);

            await contactFormsRepository.SaveChangesAsync();

            return(contactForm.Id);
        }
Esempio n. 6
0
 private async Task SendEmail(ContactFormInputModel model)
 {
     await this.emailSender.SendEmailAsync(
         GlobalConstants.SingleSenderEmail,
         model.Name,
         GlobalConstants.SystemEmail,
         model.Title,
         model.Content);
 }
Esempio n. 7
0
        public IActionResult PostMessage(ContactFormInputModel model)
        {
            if (model == null)
            {
                return(BadRequest("You tried to send a message without providing any data."));
            }

            _messageService.SendMessage(model);

            return(NoContent());
        }
        public async Task <IActionResult> ContactUs()
        {
            var aboutUsInformation = await this.aboutUsService.GetInformationAsync <AboutUsViewModel>();

            var viewModel = new ContactFormInputModel
            {
                AboutUs = aboutUsInformation,
            };

            return(this.View(viewModel));
        }
Esempio n. 9
0
        public async Task <IActionResult> Index(ContactFormInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            await this.contactsService.SendEmailToAdminAsync(inputModel);

            this.TempData[GlobalConstants.RedirectedFromContactForm] = true;
            return(this.RedirectToAction(nameof(this.ThankYou)));
        }
        public async Task <IActionResult> ContactUs(ContactFormInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            await this.contactUsService.CreateAsync(input.Name, input.Email, input.Title, input.Content);

            await this.mailHelper.SendContactFormAsync(input.Email, input.Name, input.Title, input.Content);

            return(this.RedirectToAction("Index"));
        }
        public ActionResult Index(ContactFormInputModel formData)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View("Index", formData);
            }

            var ip = this.Request.ServerVariables["REMOTE_ADDR"];
            ContactForm contactForm = this.ContactFormServices.Create(formData.Name, formData.Email, formData.Subject, formData.Message, ip);
            this.TempData[WebApplicationConstants.TempDataKeyForContactForm] = SuccessSendMessage;

            return this.RedirectToAction("Index");
        }
Esempio n. 12
0
        public async Task <IActionResult> Index(ContactFormInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.emailSender
            .SendEmailAsync(model.Email, model.Name, GlobalConstants.ContactEmail, model.Subject, model.Message);

            this.TempData["SendMessage"] =
                "Your message was sent and we will review it as soon as possible! Thank you for your patience. :)";

            return(this.RedirectToAction("Index", "Home"));
        }
Esempio n. 13
0
        public async Task CreateAsync(ContactFormInputModel model, string ip)
        {
            var contactForm = new ContactForm
            {
                Name    = model.Name,
                Email   = model.Email,
                Title   = model.Title,
                Content = model.Content,
                Ip      = ip,
            };

            await this.db.ContactForms.AddAsync(contactForm);

            await this.db.SaveChangesAsync();
        }
        public async Task <IActionResult> Contact(ContactFormInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var id = await this.homeService.Create(input);

            var html = new StringBuilder();
            var name = string.IsNullOrEmpty(input.Name) ? "Anonymous" : input.Name;

            html.AppendLine($"<p>{input.Description}</p>");
            await this.emailSender.SendEmailAsync(input.Email, name, "*****@*****.**", input.Title, html.ToString());

            return(this.RedirectToAction(nameof(Index)));
        }
Esempio n. 15
0
        public async Task <IActionResult> Contact(ContactFormInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            // TODO: Extract to IP provider (service)
            var ip = this.HttpContext.Connection.RemoteIpAddress.ToString();

            await this.contactsService.CreateAsync(model, ip);

            await this.SendEmail(model);

            this.TempData["Message"] = "Successfully sent E-mail. Thank You!";

            return(this.Redirect("/Home/Index"));
        }
Esempio n. 16
0
        public async Task DoesSendEmailToAdminAsyncWorkCorrectly()
        {
            var list = new List <ContactForm>();

            var service = this.CreateMockAndConfigureService(list, new List <ContactFormReply>());

            var contactFormEntity = new ContactFormInputModel
            {
                Name    = TestContactName,
                Email   = TestContactEmail,
                Title   = TestContactTitle,
                Message = TestContactMessage,
            };

            await service.SendEmailToAdminAsync(contactFormEntity);

            Assert.Equal(TestContactName, list.First().Name);
        }
Esempio n. 17
0
        public async Task DoesSendEmailToAdminAsyncThrowsArgumentExceptionWhenSuchContactAlreadyExists()
        {
            var list = new List <ContactForm>();

            var service = this.CreateMockAndConfigureService(list, new List <ContactFormReply>());

            var contactFormEntity = new ContactFormInputModel
            {
                Name    = TestContactName,
                Email   = TestContactEmail,
                Title   = TestContactTitle,
                Message = TestContactMessage,
            };

            await service.SendEmailToAdminAsync(contactFormEntity);

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.SendEmailToAdminAsync(contactFormEntity));
        }
Esempio n. 18
0
        public async Task <IActionResult> ContactForm(ContactFormInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            QuestionServiceModel model        = input.To <QuestionServiceModel>();
            ClaimsPrincipal      userIdentity = this.User;

            if (input.UserEmail == userIdentity.Identity.Name)
            {
                model.SystemUserId = this.userManager.GetUserId(userIdentity);
            }

            await this.questionsService.CreateMessage(userIdentity, model);

            return(this.Redirect("/"));
        }
        public async Task <IActionResult> Contact(ContactFormInputModel contactFormInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var model = new ContactFormServiceModel
            {
                Name    = contactFormInputModel.Name,
                Subject = contactFormInputModel.Subject,
                Email   = contactFormInputModel.Email,
                Message = contactFormInputModel.Message,
            };

            await this.informationsService.CreateContactFormAsync(model);

            return(this.Redirect("/"));
        }
Esempio n. 20
0
        public void SendMessage(ContactFormInputModel model)
        {
            if (model == null ||
                string.IsNullOrWhiteSpace(model.Name) ||
                string.IsNullOrWhiteSpace(model.Subject) ||
                string.IsNullOrWhiteSpace(model.Email) ||
                string.IsNullOrWhiteSpace(model.Message))
            {
                throw new ArgumentException("MessageService: the argument or a property thereof was null.");
            }

            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(new MailboxAddress(
                                     "Contact Form",
                                     "*****@*****.**"));

            mimeMessage.To.Add(new MailboxAddress(
                                   "Webmaster",
                                   _configuration["ContactEmail"]));

            mimeMessage.Subject = model.Subject;

            mimeMessage.Body = new TextPart("html")
            {
                Text = FormatMessageBody(model.Name, model.Email, model.Subject, model.Message)
            };

            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);

                client.Authenticate(
                    _configuration["ContactEmail"],
                    _configuration["ContactEmailPassword"]);

                client.Send(mimeMessage);

                client.Disconnect(true);
            }
        }
Esempio n. 21
0
        public async Task <IActionResult> Contact(ContactFormInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                this.ViewData["Error"] = "Error. Please try again.";
                return(this.View());
            }

            var rqf     = this.Request.HttpContext.Features.Get <IRequestCultureFeature>();
            var culture = rqf.RequestCulture.Culture.Name;

            var adminEmail      = (await this.userManager.GetUsersInRoleAsync(GlobalConstants.AdministratorRoleName)).FirstOrDefault().Email;
            var userEmailTextEN = $"<div>Hello, </div> <div></div> <div>Your email has been received.</div><div>Thank you!</div>";
            var userEmailTextBG = $"<div>Здравей, </div> <div></div> <div>Имейлът ти е получен.</div><div>Благодаря!</div>";

            // Send emails to admin and user
            await this.emailSender.SendEmailAsync(inputModel.Email, $"{inputModel.FirstName} {inputModel.LastName}", adminEmail, GlobalConstants.SystemName, $"<div>{inputModel.Message}</div><div>Name: {inputModel.FirstName} {inputModel.LastName}</div><div>Phone: {inputModel.PhoneNumber}</div>");

            await this.emailSender.SendEmailAsync(adminEmail, GlobalConstants.SystemName, inputModel.Email, GlobalConstants.SystemName, culture == "bg"?userEmailTextBG : userEmailTextEN);

            this.TempData["StatusMessage"] = culture == "bg" ? "Имейлът ти е получен. Благодаря!" : "Your email has been received. Thank you!";
            return(this.RedirectToAction("Index"));
        }