public void UpdateContactEmail_Failed() { //Arrenge var url = baseRoute + "AddUpdateEmails"; //Act var requestModel = new ContactEmailModel { ContactID = -1, ContactEmailID = -1, Email = "*****@*****.**", EmailID = 1, EmailPermissionID = 1, IsPrimary = true, ForceRollback = true }; var requestListModel = new List <ContactEmailModel>(); requestListModel.Add(requestModel); var response = communicationManager.Post <List <ContactEmailModel>, Response <ContactEmailModel> >(requestListModel, url); //Assert Assert.IsNotNull(response, "Response cann't be null"); Assert.IsTrue(response.RowAffected > 0, "Email updated for invalid data."); }
public ActionResult Contact(ContactEmailModel cem) { if (!ModelState.IsValid) { return(View(cem)); } string message = $"Name: {cem.Name}<br/>Email: {cem.Email}<br/>Subject: {cem.Subject}<br/>Message: {cem.Message}"; MailMessage mm = new MailMessage("*****@*****.**", "*****@*****.**", cem.Subject, message); mm.IsBodyHtml = true; mm.Priority = MailPriority.High; mm.ReplyToList.Add(cem.Email); SmtpClient client = new SmtpClient("mail.ianwhitehill.com"); client.Credentials = new NetworkCredential("*****@*****.**", "1@TopGear@1"); client.Port = 8889; try { client.Send(mm); } catch (Exception ex) { ViewBag.CustomerMessage = $"We are sorry your request could not be completed at this time please try again late <br/>Error Message:<br/>{ex.StackTrace}"; return(View(cem)); } return(View("EmailConfirmation", cem)); }
public ActionResult Contact(ContactEmailModel model) { if (ModelState.IsValid) { try { String subject = model.Subject; String contents = model.Contents; ContactEmail es = new ContactEmail(); es.Send(subject, contents); ViewBag.Result = "Email has been send."; ModelState.Clear(); return(View(new ContactEmailModel())); } catch { return(View()); } } return(View()); }
public void AddContactEmail_Success() { //Arrenge var url = baseRoute + "AddUpdateEmail"; var requestModel = new ContactEmailModel { ContactID = 1, ContactEmailID = 1, Email = "*****@*****.**", EmailID = 1, EmailPermissionID = 1, IsPrimary = true, ForceRollback = true }; var requestListModel = new List <ContactEmailModel>(); requestListModel.Add(requestModel); //Act var response = communicationManager.Post <List <ContactEmailModel>, Response <ContactEmailModel> >(requestListModel, url); //Assert Assert.IsNotNull(response, "Response cann't be null"); Assert.IsTrue(response.RowAffected > 0, "Contact Demography could not be created."); }
public static ContactEmailViewModel ToViewModel(this ContactEmailModel entity) { if (entity == null) { return(null); } var model = new ContactEmailViewModel { Email = entity.Email, EmailID = entity.EmailID, EmailPermissionID = entity.EmailPermissionID, IsPrimary = entity.IsPrimary, EffectiveDate = entity.EffectiveDate, ExpirationDate = entity.ExpirationDate, IsActive = entity.IsActive, ModifiedOn = entity.ModifiedOn, ModifiedBy = entity.ModifiedBy, ForceRollback = entity.ForceRollback, ContactID = entity.ContactID, ContactEmailID = entity.ContactEmailID }; return(model); }
private void SendEmail(ContactEmailModel contactEmailModel) { var sendgrid = _context.ApiKey.Find(1); var sendGridClient = new SendGridClient(sendgrid.ApiKey1); var myMessage = new SendGridMessage(); myMessage.AddTo("*****@*****.**"); myMessage.From = new EmailAddress("*****@*****.**", "LuxeDreamEventHire"); myMessage.SetTemplateId("d-fa12e602e09041339338a5869708e195"); myMessage.SetTemplateData(new { Name = contactEmailModel.Name, Email = contactEmailModel.Email, PhoneNumber = contactEmailModel.PhoneNumber, Company = contactEmailModel.Company, DateOfEvent = contactEmailModel.DateOfEvent.ToString("D"), LocationOfEvent = contactEmailModel.LocationOfEvent, FindUs = contactEmailModel.FindUs, TypeOfEvent = contactEmailModel.TypeOfEvent, Message = contactEmailModel.Message }); var messageToCustomer = new SendGridMessage(); messageToCustomer.AddTo(contactEmailModel.Email); messageToCustomer.From = new EmailAddress("*****@*****.**", "LuxeDreamEventHire"); messageToCustomer.SetTemplateId("d-2978c7005cdb4dfd8bd47ab5e8257094"); messageToCustomer.SetTemplateData(new { Name = contactEmailModel.Name, Email = contactEmailModel.Email, PhoneNumber = contactEmailModel.PhoneNumber, Company = contactEmailModel.Company, DateOfEvent = contactEmailModel.DateOfEvent.ToString("D"), LocationOfEvent = contactEmailModel.LocationOfEvent, FindUs = contactEmailModel.FindUs, TypeOfEvent = contactEmailModel.TypeOfEvent, Message = contactEmailModel.Message }); sendGridClient.SendEmailAsync(myMessage); sendGridClient.SendEmailAsync(messageToCustomer); }
/// <summary> /// Mock_s contact Emails_ failed. /// </summary> public void Mock_ContactEmails_Failed() { Mock <IContactEmailDataProvider> mock = new Mock <IContactEmailDataProvider>(); contactEmailDataProvider = mock.Object; var contactEmails = new List <ContactEmailModel>(); contactEmailsModel = new ContactEmailModel() { ContactID = -1, ContactEmailID = -1, Email = "*****@*****.**", EmailID = 0, EmailPermissionID = 0, IsPrimary = true, }; contactEmails.Add(contactEmailsModel); var contactEmail = new Response <ContactEmailModel>() { DataItems = contactEmails }; //Get contactEmails Response <ContactEmailModel> contactEmailsResponse = new Response <ContactEmailModel>(); contactEmailsResponse.DataItems = contactEmails.Where(contact => contact.ContactID == contactId).ToList(); mock.Setup(r => r.GetEmails(It.IsAny <long>(), It.IsAny <int>())) .Returns(contactEmailsResponse); //Add contactEmails mock.Setup(r => r.AddEmails(It.IsAny <long>(), It.IsAny <List <ContactEmailModel> >())) .Callback <long, List <ContactEmailModel> >((i, p) => contactEmails.AddRange(p)) .Returns(contactEmail); //Update contactEmails mock.Setup(r => r.UpdateEmails(It.IsAny <long>(), It.IsAny <List <ContactEmailModel> >())) .Callback <long, List <ContactEmailModel> >((i, p) => contactEmails.AddRange(p)) .Returns(contactEmail); //Delete Contact Email mock.Setup(r => r.DeleteEmail(It.IsAny <long>())) .Callback <long>(t => contactEmails.Remove(contactEmails.Find(c => c.ContactEmailID == t))) .Returns(contactEmail); }
public void Initialize() { communicationManager = new CommunicationManager("X-Token", ConfigurationManager.AppSettings["UnitTestToken"]); communicationManager.UnitTestUrl = ConfigurationManager.AppSettings["UnitTestUrl"]; requestModel = new ContactEmailModel { ContactID = 1, ContactEmailID = 1, Email = "*****@*****.**", EmailID = 1, EmailPermissionID = 1, IsPrimary = true, }; requestModel.ForceRollback = true; requestListModel = new List <ContactEmailModel>(); requestListModel.Add(requestModel); }
// GET: ContactUs public async Task <ActionResult> Index(ContactEmailModel model) { if (ModelState.IsValid) { try { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); //message.From = new MailAddress("*****@*****.**"); message.From = new MailAddress(model.FromEmail); message.To.Add(new MailAddress("*****@*****.**")); message.Subject = model.Subject; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { smtp.UseDefaultCredentials = true; var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); ModelState.Clear(); return(RedirectToAction("Sent")); } } catch (Exception ex) { ModelState.Clear(); ViewBag.Message = $" Sorry we are facing Problem here {ex.Message}"; } } return(View(model)); }
public async Task <ActionResult <ContactEmail> > PostContactEmail(ContactEmailModel contactEmailModel) { var result = new Result <ContactEmail>(); ContactEmail contactEmail = new ContactEmail(); _mapper.Map(contactEmailModel, contactEmail); result.Data = contactEmail; await _context.ContactEmail.AddAsync(contactEmail); try { SendEmail(contactEmailModel); await _context.SaveChangesAsync(); } catch (Exception e) { result.ErrorMessage = e.Message; result.IsFound = false; return(BadRequest(result)); } return(Ok(result)); }
public ActionResult SendEmail(ContactEmailModel contactUs) { return Json(true, JsonRequestBehavior.AllowGet); }