public void SaveField() { if (DynamicField.Controls.Count == 0) { return; } var control = DynamicField.Controls[0]; if (control is WebApplication.Admin.Controls.Fields.IFieldControl) { var ctrl = ((WebApplication.Admin.Controls.Fields.IFieldControl)control); var value = ctrl.GetValue(); if (value is string) { var str = value.ToString(); str = MediaDetailsMapper.ConvertUrlsToShortCodes(str); Field.FieldValue = str; } ctrl.SetValue(value); } else { try { Field.FieldValue = ParserHelper.ParseData("{" + Field.GetAdminControlValue + "}", control); } catch (Exception ex) { DisplayErrorMessage("Error", ErrorHelper.CreateError(ex)); } } if (Field.MediaTypeField != null && Field.UseMediaTypeFieldFrontEndLayout) { Field.MediaTypeField.FrontEndLayout = FrontEndLayout.Text; } else { Field.FrontEndLayout = FrontEndLayout.Text; } var returnObj = FieldsMapper.Update(Field); if (returnObj.IsError) { DisplayErrorMessage("Error", returnObj.Error); } else { Field.MediaDetail.RemoveFromCache(); DisplaySuccessMessage("Successfully saved"); } }
protected void ClearAllSubmissions_Click(object sender, EventArgs e) { var field = GetField(); field.FrontEndSubmissions = ""; var returnObj = FieldsMapper.Update(field); if (!returnObj.IsError) { FormSubmissions.DataSource = new DataTable(); FormSubmissions.DataBind(); } }
public void FieldSettingsSubmissionHandler() { var returnObj = BaseMapper.GenerateReturn("No action performed"); if (HttpContext.Current.Request.Form["fieldId"] == null) { returnObj = BaseMapper.GenerateReturn("'fieldId' is missing"); WriteJSON(returnObj.ToJson()); } if (!long.TryParse(HttpContext.Current.Request.Form["fieldId"], out long fieldId)) { returnObj = BaseMapper.GenerateReturn("Invalid 'fieldId'"); WriteJSON(returnObj.ToJson()); } var field = FieldsMapper.GetByID(fieldId); if (field == null) { returnObj = BaseMapper.GenerateReturn($"Cannot find field with id '{fieldId}'"); WriteJSON(returnObj.ToJson()); } var FormDictionary = new Dictionary <string, string>(); foreach (string key in HttpContext.Current.Request.Form.Keys) { FormDictionary.Add(key, HttpContext.Current.Request.Form[key]); } FormDictionary.Add("DateLastModified", StringHelper.FormatDateTime(DateTime.Now)); var jsonEntry = new JavaScriptSerializer().Serialize(FormDictionary); field.FieldSettings = jsonEntry; returnObj = FieldsMapper.Update(field); WriteJSON(returnObj.ToJson()); }
protected void SaveSettings_Click(object sender, EventArgs e) { var field = GetField(); var formFieldsSettings = new FormFieldSettings(); formFieldsSettings.EmailAddress = EmailAddress.Text; formFieldsSettings.EmailTemplateMediaID = EmailTemplateMediaID.Text; formFieldsSettings.Subject = Subject.Text; var jsonSettings = StringHelper.ObjectToJson(formFieldsSettings); field.FieldSettings = jsonSettings; var returnObj = FieldsMapper.Update(field); if (!returnObj.IsError) { BasePage.DisplaySuccessMessage("Successfully saved field settings"); } else { BasePage.DisplayErrorMessage(returnObj.Error.Message); } }
public Return FieldFrontEndFormSubmissionHandler(long fieldId) { var returnObj = BaseMapper.GenerateReturn("No action performed"); if (HttpContext.Current.Request.Form["fieldId"] == null) { returnObj = BaseMapper.GenerateReturn("'fieldId' is missing"); return(returnObj); } var field = (MediaDetailField)FieldsMapper.GetByID(fieldId); if (field == null) { returnObj = BaseMapper.GenerateReturn($"Cannot find field with id '{fieldId}'"); return(returnObj); } var FormDictionary = new Dictionary <string, string>(); foreach (string key in HttpContext.Current.Request.Form.Keys) { var value = HttpContext.Current.Request.Form[key]; if (value.Contains(",")) { value = "\"" + value + "\""; } FormDictionary.Add(key, value); } FormDictionary.Add("DateSubmitted", StringHelper.FormatDateTime(DateTime.Now)); var currentEntries = StringHelper.JsonToObject <Newtonsoft.Json.Linq.JArray>(field.FrontEndSubmissions); var files = new Dictionary <string, List <string> >(); var fileIndex = 0; foreach (string key in HttpContext.Current.Request.Files) { var postedFile = HttpContext.Current.Request.Files[fileIndex]; var uploadFolder = MediaDetailField.GetUploadFolder(field); if (!uploadFolder.Exists) { uploadFolder.Create(); } var fieldName = postedFile.FileName.ToLower().Replace(" ", "-"); var uploadFilePath = uploadFolder.FullName + key + "_" + fieldName; postedFile.SaveAs(uploadFilePath); var relativePath = URIHelper.ConvertAbsPathToAbsUrl(uploadFilePath); if (files.ContainsKey(key)) { files[key].Add(relativePath); } else { files.Add(key, new List <string>() { relativePath }); } fileIndex++; } var jObjectUploadFiles = JObject.Parse(StringHelper.ObjectToJson(files)); var jsonEntry = new JavaScriptSerializer().Serialize(FormDictionary); var jObject = JObject.Parse(jsonEntry); jObject.Merge(jObjectUploadFiles); if (currentEntries == null) { currentEntries = new JArray(); currentEntries.Add(jObject); } else { currentEntries.Add(jObject); } field.FrontEndSubmissions = currentEntries.ToString(Formatting.None); returnObj = FieldsMapper.Update(field); var formFieldSettings = StringHelper.JsonToObject <FormFieldSettings>(field.FieldSettings); if (formFieldSettings != null && !string.IsNullOrEmpty(formFieldSettings.EmailTemplateMediaID) && long.TryParse(formFieldSettings.EmailTemplateMediaID, out long i)) { var media = MediasMapper.GetByID(long.Parse(formFieldSettings.EmailTemplateMediaID)); if (media != null) { var layout = MediaDetailsMapper.ParseSpecialTags(media.GetLiveMediaDetail()); var parsedLayout = ParserHelper.ParseData(layout, jObject); EmailHelper.Send(AppSettings.SystemEmailAddress, EmailHelper.GetMailAddressesFromString(formFieldSettings.EmailAddress), formFieldSettings.Subject, parsedLayout, (AppSettings.AttemptSMTPMailer)? EmailHelper.EmailMode.Both : EmailHelper.EmailMode.Direct); } } return(returnObj); }