public static void SubmitForm(string firstName, string lastName, string email, string phone, string company, string message, string ipAddress, Guid userId, string formName) { Dictionary <string, string> inputs = new Dictionary <string, string>(); inputs.Add("FirstName", firstName); inputs.Add("LastName", lastName); inputs.Add("Email", email); inputs.Add("PhoneNumber", phone); inputs.Add("Company", company); inputs.Add("Message", message); FormsManager manager = FormsManager.GetManager(); var form = manager.GetFormByName(formName); FormEntry entry = manager.CreateFormEntry(form.EntriesTypeName); foreach (var item in inputs) { entry.SetValue(item.Key, item.Value); } entry.IpAddress = ipAddress; entry.UserId = userId; if (AppSettings.CurrentSettings.Multilingual) { entry.Language = System.Globalization.CultureInfo.CurrentUICulture.Name; } entry.ReferralCode = (manager.Provider.GetNextReferralCode(entry.GetType().ToString())).ToString(); entry.SubmittedOn = System.DateTime.UtcNow; manager.SaveChanges(); }
new private void SaveFormEntry(FormDescription description) { FormsManager manager = FormsManager.GetManager(); FormEntry userHostAddress = null; if (_isProgressiveForm && _priorFormEntry == null) { FieldControl keyField = this.FieldControls.Where(fc => ((IFormFieldControl)fc).MetaField.FieldName == _progressiveKeyFieldName).FirstOrDefault() as FieldControl; if (keyField != null && !String.IsNullOrWhiteSpace((string)keyField.Value)) { _priorFormEntry = GetPriorFormEntryByKeyField((string)keyField.Value); } } if (_isProgressiveForm && _priorFormEntry != null) { string entryType = String.Format("{0}.{1}", manager.Provider.FormsNamespace, this.FormData.Name); userHostAddress = manager.GetFormEntry(entryType, _priorFormEntry.Id); } else { userHostAddress = manager.CreateFormEntry(string.Format("{0}.{1}", manager.Provider.FormsNamespace, description.Name)); } foreach (IFormFieldControl formFieldControl in this.FieldControls) { FieldControl fieldControl = formFieldControl as FieldControl; object value = fieldControl.Value; if (fieldControl.GetType().Name == "FormFileUpload") { typeof(FormsControl) .GetMethod("SaveFiles", BindingFlags.Static | BindingFlags.NonPublic) .Invoke(null, new object[] { value as UploadedFileCollection, manager, description, userHostAddress, formFieldControl.MetaField.FieldName }); } else if (!(value is List <string>)) { userHostAddress.SetValue(formFieldControl.MetaField.FieldName, value); } else { StringArrayConverter stringArrayConverter = new StringArrayConverter(); object obj = stringArrayConverter.ConvertTo((value as List <string>).ToArray(), typeof(string)); userHostAddress.SetValue(formFieldControl.MetaField.FieldName, obj); } } userHostAddress.IpAddress = this.Page.Request.UserHostAddress; userHostAddress.SubmittedOn = DateTime.UtcNow; Guid userId = ClaimsManager.GetCurrentUserId(); userHostAddress.UserId = userId == Guid.Empty ? Guid.Parse(_sfTrackingCookie.Value) : userId; if (userHostAddress.UserId == userId) { userHostAddress.Owner = userId; } if (SystemManager.CurrentContext.AppSettings.Multilingual) { userHostAddress.Language = CultureInfo.CurrentUICulture.Name; } FormDescription formData = this.FormData; formData.FormEntriesSeed = formData.FormEntriesSeed + (long)1; userHostAddress.ReferralCode = this.FormData.FormEntriesSeed.ToString(); manager.SaveChanges(); }
new private void SaveFormEntry(FormDescription description) { FormsManager manager = FormsManager.GetManager(); FormEntry userHostAddress = null; if (_isProgressiveForm && _priorFormEntry == null) { FieldControl keyField = this.FieldControls.Where(fc => ((IFormFieldControl)fc).MetaField.FieldName == _progressiveKeyFieldName).FirstOrDefault() as FieldControl; if (keyField != null && !String.IsNullOrWhiteSpace((string)keyField.Value)) { _priorFormEntry = GetPriorFormEntryByKeyField((string)keyField.Value); } } if (_isProgressiveForm && _priorFormEntry != null) { string entryType = String.Format("{0}.{1}", manager.Provider.FormsNamespace, this.FormData.Name); userHostAddress = manager.GetFormEntry(entryType, _priorFormEntry.Id); } else { userHostAddress = manager.CreateFormEntry(string.Format("{0}.{1}", manager.Provider.FormsNamespace, description.Name)); } foreach (IFormFieldControl formFieldControl in this.FieldControls) { FieldControl fieldControl = formFieldControl as FieldControl; object value = fieldControl.Value; if (fieldControl.GetType().Name == "FormFileUpload") { if (formFieldControl.MetaField.FieldName != "") { var uploadValue = value as UploadedFileCollection; var files = new Dictionary <string, List <FormHttpPostedFile> >(); List <FormHttpPostedFile> formHttpPostedFileList = new List <FormHttpPostedFile>(); foreach (UploadedFile uploadedFile in uploadValue) { if (uploadedFile != null) { formHttpPostedFileList.Add(new FormHttpPostedFile() { FileName = uploadedFile.FileName, InputStream = uploadedFile.InputStream, ContentType = uploadedFile.ContentType, ContentLength = uploadedFile.ContentLength }); } } files.Add(formFieldControl.MetaField.FieldName, formHttpPostedFileList); var type = Type.GetType("Telerik.Sitefinity.Modules.Forms.Web.FormsHelper,Telerik.Sitefinity"); var method = type.GetMethod("SaveFiles", BindingFlags.Static | BindingFlags.NonPublic); var updateMode = _priorFormEntry != null; method.Invoke(null, new object[] { files, description, userHostAddress, updateMode }); } } else if (!(value is List <string>)) { userHostAddress.SetValue(formFieldControl.MetaField.FieldName, value); } else { StringArrayConverter stringArrayConverter = new StringArrayConverter(); object obj = stringArrayConverter.ConvertTo((value as List <string>).ToArray(), typeof(string)); userHostAddress.SetValue(formFieldControl.MetaField.FieldName, obj); } } userHostAddress.IpAddress = this.Page.Request.UserHostAddress; userHostAddress.SubmittedOn = DateTime.UtcNow; Guid userId = ClaimsManager.GetCurrentUserId(); userHostAddress.UserId = userId == Guid.Empty ? Guid.Parse(_sfTrackingCookie.Value) : userId; if (userHostAddress.UserId == userId) { userHostAddress.Owner = userId; } if (SystemManager.CurrentContext.AppSettings.Multilingual) { userHostAddress.Language = CultureInfo.CurrentUICulture.Name; } FormDescription formData = this.FormData; formData.FormEntriesSeed = formData.FormEntriesSeed + (long)1; userHostAddress.ReferralCode = this.FormData.FormEntriesSeed.ToString(); manager.SaveChanges(); }