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 Page_Init(object sender, EventArgs e) { var fieldIdStr = Request["fieldId"]; if (!string.IsNullOrEmpty(fieldIdStr)) { if (!CurrentUser.HasPermission(PermissionsEnum.AccessAdvanceOptions)) { LayoutsTab.Visible = false; FrontEndLayout.Visible = false; } var fieldId = long.Parse(fieldIdStr); var field = FieldsMapper.GetByID(fieldId); if (field != null && field is MediaDetailField) { Field = field as MediaDetailField; LoadField(); } } }
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); }