public ActionResult SubmitForm(string f, string referredUrl, bool isAjaxRequest = false) { var contact = new Contact(); var communication = new ContactCommunication(); TryUpdateModel(contact); TryUpdateModel(communication); var response = _formService.SubmitForm(f, contact, communication, HttpContext.Request.Form); if (isAjaxRequest) { //Allow cross domain submit HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", "*"); return(Json(response)); } if (string.IsNullOrEmpty(referredUrl)) { return(RedirectToAction("IframeLoader", new { f, formSubmitted = true })); } if (response.Success) { referredUrl = referredUrl.AddQueryParam("formSubmitted", "true"); } return(Redirect(referredUrl)); }
public ContactCommunicationManageModel(ContactCommunication contactCommunication) : this() { Id = contactCommunication.Id; ContactId = contactCommunication.ContactId; ContactName = contactCommunication.Contact.FullName; ReferredBy = contactCommunication.ReferredBy; CampaignCode = contactCommunication.CampaignCode; ProductOfInterest = contactCommunication.ProductOfInterest; InterestedInOwning = contactCommunication.InterestedInOwning; TimeFrameToOwn = contactCommunication.TimeFrameToOwn; Certification = contactCommunication.Certification; CurrentlyOwn = contactCommunication.CurrentlyOwn; PurchaseDate = contactCommunication.PurchaseDate; SubscriberType = contactCommunication.SubscriberType; Comments = contactCommunication.Comments; }
/// <summary> /// Save from /// </summary> /// <param name="contact"></param> /// <param name="communication"></param> /// <param name="formData"></param> public Contact SaveForm(Contact contact, ContactCommunication communication, List <ContactInformation> formData) { #region Parse Data var fullname = formData.FirstOrDefault(k => k.Key.Equals("FullName")); if (fullname != null && string.IsNullOrEmpty(contact.FirstName) && string.IsNullOrEmpty(contact.LastName)) { string firstName; string lastName; fullname.Value.GenerateName(out firstName, out lastName); contact.FirstName = firstName; contact.LastName = lastName; } #endregion #region Generate contact var currentContact = CreateContactIfNotExists(contact); if (currentContact != null) { Mapper.CreateMap <Contact, Contact>() .ForMember(c => c.Id, opt => opt.Ignore()) .ForMember(c => c.Created, opt => opt.Ignore()) .ForAllMembers(opt => opt.Condition(srs => !srs.IsSourceValueNull)); Mapper.Map(contact, currentContact); currentContact.Company = _companyService.SaveCompany(contact.Company); Update(currentContact); } if (currentContact != null && communication != null) { communication.ContactId = currentContact.Id; _contactCommunicationService.Insert(communication); } #endregion WorkContext.CurrentContact = new ContactCookieModel(currentContact); return(currentContact); }
//.Include(x=> x.) //.Include(x=> x.) public void Save(ContactCommunication model) { var now = DateTime.Now; if (model.ContactCommunicationId != 0) { model.CreationDate = now; model.Communication.CreationDate = now; _context.ContactCommunication.Update(model); } else { model.UpgradeDate = now; model.Communication.UpgradeDate = now; model.Communication.StatusId = StatusValues.Activo; model.StatusId = StatusValues.Activo; _context.Add(model); } _context.SaveChanges(); }
public ContactCommunicationModel(ContactCommunication contactCommunication) : this() { Id = contactCommunication.Id; CurrentlyOwn = contactCommunication.CurrentlyOwn; InterestedInOwning = contactCommunication.InterestedInOwning; ProductOfInterest = contactCommunication.ProductOfInterest; PurchaseDate = contactCommunication.PurchaseDate; CampaignCode = contactCommunication.CampaignCode; Certification = contactCommunication.Certification; SubscriberType = contactCommunication.SubscriberType; ReferredBy = contactCommunication.ReferredBy; TimeFrameToOwn = contactCommunication.TimeFrameToOwn; RecordOrder = contactCommunication.RecordOrder; Created = contactCommunication.Created; CreatedBy = contactCommunication.CreatedBy; LastUpdate = contactCommunication.LastUpdate; LastUpdateBy = contactCommunication.LastUpdateBy; }
/// <summary> /// Save contact form /// </summary> /// <param name="contact"></param> /// <param name="communication"></param> /// <param name="form"></param> /// <returns></returns> public ResponseModel SaveContactForm(Contact contact, ContactCommunication communication, NameValueCollection form) { var formData = form.AllKeys.SelectMany(form.GetValues, (k, v) => new ContactInformation { Key = k, Value = v }).ToList(); // Save contact SaveForm(contact, communication, formData); #region Generate emails var emailFrom = formData.FirstOrDefault(f => f.Key.Equals("EmailFrom")); var emailTo = formData.FirstOrDefault(f => f.Key.Equals("EmailTo")); if (emailTo != null && !string.IsNullOrEmpty(emailTo.Value)) { var contactInformation = formData.Where(f => !f.Key.Equals("EmailFrom") && !f.Key.Equals("EmailTo")).ToList(); var model = new ContactFormEmailModel { Email = contact.Email, FullName = string.Format("{0} {1}", contact.FirstName, contact.LastName), ContactInformation = contactInformation }; var emailResponse = _emailTemplateService.ParseEmail(EmailEnums.EmailTemplateType.ContactForm, model); if (emailResponse == null) { return(new ResponseModel { Success = false, Message = T("Contact_Message_MissingContactFormEmailTemplate") }); } var emailLog = new EmailLog { To = emailTo.Value, ToName = emailTo.Value, From = emailFrom == null ? string.Empty : emailFrom.Value, FromName = emailFrom == null ? string.Empty : emailFrom.Value, CC = emailResponse.CC, Bcc = emailResponse.BCC, Subject = emailResponse.Subject, Body = emailResponse.Body, Priority = EmailEnums.EmailPriority.Medium }; var response = _emailLogService.CreateEmail(emailLog, true); return(response.Success ? response.SetMessage(T("Contact_Message_ContactFormActionSuccessfully")) : response.SetMessage(T("Contact_Message_ContactFormActionFailure"))); } #endregion return(new ResponseModel { Success = true, Message = T("Contact_Message_ContactFormActionSuccessfully") }); }
private void AddCommunication(DeepBlue.Models.Entity.Contact contact, DeepBlue.Models.Admin.Enums.CommunicationType communicationType, string value) { // Attempt to create contact communication. ContactCommunication contactCommunication = contact.ContactCommunications.SingleOrDefault(communication => communication.Communication.CommunicationTypeID == (int)communicationType); if (contactCommunication == null) { contactCommunication = new ContactCommunication(); contactCommunication.CreatedBy = Authentication.CurrentUser.UserID; contactCommunication.CreatedDate = DateTime.Now; contactCommunication.Communication = new Communication(); contactCommunication.Communication.CreatedBy = Authentication.CurrentUser.UserID; contactCommunication.Communication.CreatedDate = DateTime.Now; contact.ContactCommunications.Add(contactCommunication); } contactCommunication.EntityID = Authentication.CurrentEntity.EntityID; contactCommunication.LastUpdatedBy = Authentication.CurrentUser.UserID; contactCommunication.LastUpdatedDate = DateTime.Now; contactCommunication.Communication.CommunicationTypeID = (int)communicationType; contactCommunication.Communication.CommunicationValue = (string.IsNullOrEmpty(value) == false ? value : string.Empty); contactCommunication.Communication.LastUpdatedBy = Authentication.CurrentUser.UserID; contactCommunication.Communication.LastUpdatedDate = DateTime.Now; contactCommunication.Communication.EntityID = Authentication.CurrentEntity.EntityID; }
private static void AddCommunication(DeepBlue.Models.Entity.Contact contact, DeepBlue.Models.Admin.Enums.CommunicationType communicationType, string value) { if (!string.IsNullOrEmpty(value)) { ContactCommunication contactComm = new ContactCommunication(); Communication comm = new Communication(); comm.CommunicationTypeID = (int)communicationType; comm.CommunicationValue = value; contactComm.Communication = comm; contact.ContactCommunications.Add(contactComm); } }
internal ResponseModel Delete(ContactCommunication contactCommunication) { return(_contactCommunicationRepository.Delete(contactCommunication)); }
public ResponseModel Update(ContactCommunication contactCommunication) { return(_contactCommunicationRepository.Update(contactCommunication)); }
public ResponseModel Insert(ContactCommunication contactCommunication) { return(_contactCommunicationRepository.Insert(contactCommunication)); }
public ActionResult SaveContact(Contact contact, ContactCommunication communication) { var response = _contactService.SaveContactForm(contact, communication, HttpContext.Request.Form); return(Json(response)); }
/// <summary> /// Submit form /// </summary> /// <param name="formId"></param> /// <param name="contact"></param> /// <param name="communication"></param> /// <param name="collection"></param> /// <returns></returns> public ResponseModel SubmitForm(string formId, Contact contact, ContactCommunication communication, NameValueCollection collection) { try { var id = PasswordUtilities.ComplexDecrypt(formId).ToInt(); var form = GetById(id); if (form != null) { var formData = collection.AllKeys.SelectMany(collection.GetValues, (k, v) => new ContactInformation { Key = k, Value = v }).ToList(); //Save contact and communication contact = _contactService.SaveForm(contact, communication, formData); #region Form Data var formEmailModel = collection.AllKeys.SelectMany(collection.GetValues, (k, v) => new ContactInformation { Key = k.CamelFriendly(), Value = v }).ToList(); var formBuilderSetting = _siteSettingService.LoadSetting <FormBuilderSetting>(); var cacheName = SettingNames.FormBuilderSetting.GetTemplateCacheName(formBuilderSetting.SubmitFormBodyTemplate); var formDataBody = RazorEngineHelper.CompileAndRun(formBuilderSetting.SubmitFormBodyTemplate, formEmailModel, null, cacheName); #endregion if (form.SendSubmitFormEmail && !string.IsNullOrEmpty(form.EmailTo)) { var email = new EmailLog { From = form.FromEmail, FromName = form.FromName, To = form.EmailTo, ToName = form.EmailTo, Subject = formBuilderSetting.SubmitFormSubject, Body = formDataBody }; _emailLogService.CreateEmail(email, true); } if (form.SendNotificationEmail && !string.IsNullOrEmpty(form.NotificationEmailTo)) { var notificationBodyStringBuilder = new StringBuilder(); notificationBodyStringBuilder.AppendLine(form.NotificationBody); notificationBodyStringBuilder.AppendLine(formDataBody); var email = new EmailLog { From = form.FromEmail, FromName = form.FromName, To = form.NotificationEmailTo, ToName = form.NotificationEmailTo, Subject = form.NotificationSubject, Body = notificationBodyStringBuilder.ToString() }; _emailLogService.CreateEmail(email, true); } if (form.SendAutoResponse) { // Get email from form data var emailAddress = formData.FirstOrDefault( f => f.Key.Contains("Email", StringComparison.CurrentCultureIgnoreCase)); if (emailAddress != null && !string.IsNullOrEmpty(emailAddress.Value)) { var toName = contact.FullName; var email = new EmailLog { From = form.FromEmail, FromName = form.FromName, To = emailAddress.Value, ToName = string.IsNullOrWhiteSpace(toName) ? emailAddress.Value : toName, Subject = form.AutoResponseSubject, Body = form.AutoResponseBody }; _emailLogService.CreateEmail(email, true); } } return(new ResponseModel { Success = true, Message = form.ThankyouMessage }); } } catch (Exception) { // Form parameters invalid } return(new ResponseModel { Success = false, Message = T("Form_Message_InvalidFormId") }); }
public IActionResult Guardar(AgentModel model) { var data = CopyPropierties.Convert <AgentModel, Agent>(model); var contactComunicationModel = new ContactCommunication(); data.Contact.ContactCommunication.ContactId = model.ContactId; if (ModelState.IsValid) { if (_contact.CheckIfContactDocumentNumberExits(data.Contact)) { EnviarMensaje.Enviar(TempData, "red", "Ya existe un registro con este número documento"); ViewBag.ContactType = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName"); ViewBag.AgentType = new SelectList(_agentType.GetAll, "AgentTypeId", "AgentTypeName"); ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName"); ViewBag.AddressType = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName"); ViewBag.Countries = new SelectList(_country.GetAll, "CountryId", "CountryName"); ViewBag.Provinces = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName"); ViewBag.Cities = new SelectList(_city.Cities, "CityId", "CityName"); ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName"); return(View("Crear", model)); } try { _agent.Save(data); } catch (Exception e) { ViewBag.ContactType = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName"); ViewBag.AgentType = new SelectList(_agentType.GetAll, "AgentTypeId", "AgentTypeName"); ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName"); ViewBag.AddressType = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName"); ViewBag.Countries = new SelectList(_country.GetAll, "CountryId", "CountryName"); ViewBag.Provinces = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName"); ViewBag.Cities = new SelectList(_city.Cities, "CityId", "CityName"); ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName"); return(View("Crear", model)); } } else { var erros = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count() > 0).First(); EnviarMensaje.Enviar(TempData, "red", erros.ErrorMessage); ViewBag.ContactType = new SelectList(_contactType.GetAll, "ContactTypeId", "ContactTypeName"); ViewBag.AgentType = new SelectList(_agentType.GetAll, "AgentTypeId", "AgentTypeName"); ViewBag.DocumentType = new SelectList(_documentType.GetAll, "DocumentTypeId", "DocumentTypeName"); ViewBag.AddressType = new SelectList(_addressType.addressTypes, "AddressTypeId", "AddressTypeName"); ViewBag.Countries = new SelectList(_country.GetAll, "CountryId", "CountryName"); ViewBag.Provinces = new SelectList(_province.Provinces, "ProvinceId", "ProvinceName"); ViewBag.Cities = new SelectList(_city.Cities, "CityId", "CityName"); ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName"); return(View("Crear", model)); } return(View("Index", _agent.Agents.DistinctBy(x => x.AgentId).ToList())); }