/// <summary> /// gets a display text value from WebForm value fields using their data type and returns a user readable string /// </summary> /// <param name="response"></param> /// <returns></returns> public static string ValueText(this WebFormFieldResponse response) { if (response == null) { return(null); } string text = string.Empty; switch (response.DataType) { case GStoreValueDataType.CheckboxYesNo: text = response.Value1Bool.HasValue ? response.Value1Bool.ToString() : "(blank)"; break; case GStoreValueDataType.ValueListItemDropdown: case GStoreValueDataType.ValueListItemRadio: text = response.Value1ValueListItemName; break; case GStoreValueDataType.ValueListItemMultiCheckbox: text = response.Value1ValueListItemNameList; break; case GStoreValueDataType.Integer: text = response.Value1Int.HasValue ? response.Value1Int.ToString() : "(blank)"; break; case GStoreValueDataType.Decimal: text = response.Value1Decimal.HasValue ? response.Value1Decimal.ToString() : "(blank)"; break; case GStoreValueDataType.IntegerRange: text = (response.Value1Int.HasValue ? response.Value1Int.ToString() : "(blank)") + " to " + (response.Value2Int.HasValue ? response.Value2Int.ToString() : "(blank)"); break; case GStoreValueDataType.DecimalRange: text = (response.Value1Decimal.HasValue ? response.Value1Decimal.ToString() : "(blank)") + " to " + (response.Value2Decimal.HasValue ? response.Value2Decimal.ToString() : "(blank)"); break; default: text = string.IsNullOrEmpty(response.Value1String) ? "(blank)" : response.Value1String; break; } return(text); }
public static void SetValueFieldsFromFormValues(this WebFormFieldResponse data, HttpRequestBase request) { if (data == null) { throw new ArgumentNullException("webFormFieldResponse"); } if (request == null) { throw new ArgumentNullException("webFormFieldResponse"); } if (data.WebFormField == null) { throw new ArgumentException("webFormFieldResponse.WebFormField is null. Be sure to set webFormFieldResponse.WebFormField object before calling this method", "webFormFieldResponse.WebFormField"); } if (!Enum.IsDefined(typeof(GStoreValueDataType), data.DataType)) { throw new ArgumentException("webFormFieldResponse.DataType value '" + data.DataType.ToString() + "' is invalid. is null. Be sure to set this value on the webFormFieldResponse object before calling this method", "webFormFieldResponse.DataType"); } data.Value1String = request.GetFormFieldValue1String(data.WebFormField); data.Value2String = request.GetFormFieldValue2String(data.WebFormField); switch (data.DataType) { case GStoreValueDataType.EmailAddress: //do nothing string value already set case GStoreValueDataType.Url: //do nothing string value already set case GStoreValueDataType.CheckboxYesNo: if (!string.IsNullOrWhiteSpace(data.Value1String)) { if ( data.Value1String.Trim().ToLower() == "1" || data.Value1String.Trim().ToLower() == "true" || data.Value1String.Trim().ToLower() == "t" || data.Value1String.Trim().ToLower() == "y" || data.Value1String.Trim().ToLower() == "yes" || data.Value1String.Trim().ToLower() == "checked" || data.Value1String.Trim().ToLower() == "check" ) { data.Value1Bool = true; } else { data.Value1Bool = false; } } break; case GStoreValueDataType.Integer: if (!string.IsNullOrWhiteSpace(data.Value1String)) { int result; if (int.TryParse(data.Value1String, out result)) { data.Value1Int = result; } } break; case GStoreValueDataType.Decimal: if (!string.IsNullOrWhiteSpace(data.Value1String)) { decimal result; if (decimal.TryParse(data.Value1String, out result)) { data.Value1Decimal = result; } } break; case GStoreValueDataType.IntegerRange: if (!string.IsNullOrWhiteSpace(data.Value1String)) { int result1; if (int.TryParse(data.Value1String, out result1)) { data.Value1Int = result1; } } if (!string.IsNullOrWhiteSpace(data.Value2String)) { int result2; if (int.TryParse(data.Value2String, out result2)) { data.Value2Int = result2; } } break; case GStoreValueDataType.DecimalRange: if (!string.IsNullOrWhiteSpace(data.Value1String)) { decimal result1; if (decimal.TryParse(data.Value1String, out result1)) { data.Value1Decimal = result1; } } if (!string.IsNullOrWhiteSpace(data.Value2String)) { decimal result2; if (decimal.TryParse(data.Value2String, out result2)) { data.Value2Decimal = result2; } } break; case GStoreValueDataType.SingleLineText: //do nothing string value already set break; case GStoreValueDataType.MultiLineText: //do nothing string value already set break; case GStoreValueDataType.Html: //do nothing string value already set break; case GStoreValueDataType.ValueListItemDropdown: if (!string.IsNullOrWhiteSpace(data.Value1String)) { int result; if (int.TryParse(data.Value1String, out result)) { if (result != 0) { data.Value1ValueListItemId = result; data.Value1ValueListItemName = data.WebFormField.GetValueListItemName(data.Value1String); } } } break; case GStoreValueDataType.ValueListItemRadio: if (!string.IsNullOrWhiteSpace(data.Value1String)) { int result; if (int.TryParse(data.Value1String, out result)) { if (result != 0) { data.Value1ValueListItemId = result; data.Value1ValueListItemName = data.WebFormField.GetValueListItemName(data.Value1String); } } } break; case GStoreValueDataType.ValueListItemMultiCheckbox: if (!string.IsNullOrWhiteSpace(data.Value1String)) { int result; string[] split = data.Value1String.Split(','); foreach (string value in split) { if (!string.IsNullOrWhiteSpace(value)) { if (int.TryParse(value.Trim(), out result)) { if (result != 0) { if (!string.IsNullOrEmpty(data.Value1ValueListItemIdList)) { data.Value1ValueListItemIdList += ","; } if (!string.IsNullOrEmpty(data.Value1ValueListItemNameList)) { data.Value1ValueListItemNameList += ","; } data.Value1ValueListItemIdList += result; data.Value1ValueListItemNameList += data.WebFormField.GetValueListItemName(value); } } } } } break; case GStoreValueDataType.ExternalLinkToPage: //do nothing link url will be value 1, link text will be value 2 break; case GStoreValueDataType.ExternalLinkToImage: //do nothing link url will be value 1, link text will be value 2 break; case GStoreValueDataType.InternalLinkToPageById: if (!string.IsNullOrWhiteSpace(data.Value1String)) { int result; if (int.TryParse(data.Value1String, out result)) { if (result != 0) { data.Value1PageId = result; } } } break; case GStoreValueDataType.InternalLinkToPageByUrl: //do nothing route values will be value 1, link text will be value 2 break; case GStoreValueDataType.InternalLinkToImageByUrl: //do nothing route values will be value 1, link text will be value 2 break; default: break; } }
private static void FillWebFormResponses(BaseController controller, WebFormResponse webFormResponse, WebForm webForm, WebFormResponse oldResponseOrNull) { if (controller == null) { throw new ArgumentNullException("controller"); } IGstoreDb db = controller.GStoreDb; UserProfile userProfile = controller.CurrentUserProfileOrNull; StoreFrontConfiguration storeFrontConfiguration = controller.CurrentStoreFrontConfigOrThrow; if (webFormResponse == null) { throw new ArgumentNullException("webFormResponse"); } if (webForm == null) { throw new ArgumentNullException("webFormResponse"); } List <WebFormField> fields = webForm.WebFormFields.AsQueryable().WhereIsActive().ApplySortDefault().ToList(); foreach (WebFormField field in fields) { WebFormFieldResponse oldFieldResponse = null; WebFormFieldResponse fieldResponse = null; if (oldResponseOrNull != null) { oldFieldResponse = oldResponseOrNull.WebFormFieldResponses.SingleOrDefault(wffr => wffr.WebFormFieldId == field.WebFormFieldId); } if (oldFieldResponse != null) { fieldResponse = oldFieldResponse; } else { fieldResponse = db.WebFormFieldResponses.Create(); fieldResponse.WebFormField = field; fieldResponse.WebFormFieldId = field.WebFormFieldId; fieldResponse.SetDefaults(userProfile); } fieldResponse.ClientId = storeFrontConfiguration.ClientId; fieldResponse.Client = storeFrontConfiguration.Client; fieldResponse.StoreFrontId = storeFrontConfiguration.StoreFrontId; fieldResponse.StoreFront = storeFrontConfiguration.StoreFront; fieldResponse.DataType = field.DataType; fieldResponse.DataTypeString = field.DataTypeString; fieldResponse.IsPending = false; fieldResponse.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); fieldResponse.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); fieldResponse.WebFormFieldLabelText = field.LabelText; fieldResponse.WebFormFieldName = field.Name; fieldResponse.WebFormFieldOrder = field.Order; fieldResponse.WebFormName = field.WebForm.Name; fieldResponse.WebFormOrder = field.WebForm.Order; fieldResponse.SetValueFieldsFromFormValues(controller.Request); if (oldFieldResponse == null) { db.WebFormFieldResponses.Add(fieldResponse); } else { db.WebFormFieldResponses.Update(fieldResponse); } } }