public static bool TryGetBigMapActionList(this ModelBindingContext bindingContext, string name, ref bool hasValue, out List <int> result) { result = null; var valueObject = (bindingContext.ValueProvider as CompositeValueProvider)? .FirstOrDefault(x => x is QueryStringValueProvider)? .GetValue(name) ?? ValueProviderResult.None; if (valueObject != ValueProviderResult.None) { bindingContext.ModelState.SetModelValue(name, valueObject); if (!string.IsNullOrEmpty(valueObject.FirstValue)) { var rawValues = valueObject.FirstValue.Split(',', StringSplitOptions.RemoveEmptyEntries); if (rawValues.Length == 0) { bindingContext.ModelState.TryAddModelError(name, "List should contain at least one item."); return(false); } hasValue = true; result = new List <int>(rawValues.Length); foreach (var rawValue in rawValues) { if (!BigMapActions.TryParse(rawValue, out var action)) { bindingContext.ModelState.TryAddModelError(name, "List contains invalid bigmap action."); return(false); } hasValue = true; result.Add(action); } } } return(true); }
public static bool TryGetBigMapAction(this ModelBindingContext bindingContext, string name, ref bool hasValue, out int?result) { result = null; var valueObject = (bindingContext.ValueProvider as CompositeValueProvider)? .FirstOrDefault(x => x is QueryStringValueProvider)? .GetValue(name) ?? ValueProviderResult.None; if (valueObject != ValueProviderResult.None) { bindingContext.ModelState.SetModelValue(name, valueObject); if (!string.IsNullOrEmpty(valueObject.FirstValue)) { if (!BigMapActions.TryParse(valueObject.FirstValue, out var action)) { bindingContext.ModelState.TryAddModelError(name, "Invalid bigmap action."); return(false); } hasValue = true; result = action; } } return(true); }