public GroupDTO MapFormGroupVMToGroupDTO(FormGroupViewModel model) { return(new GroupDTO { Id = model.Id, GroupName = model.GroupName, Description = model.Description, ParentId = model.ParentId }); }
internal static IHtmlContent GenerateHtml <TModel, TProperty>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null, TextInputAppendixViewModel textInputAppendix = null, string type = "text", string autocomplete = null ) where TModel : GovUkViewModel { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; string currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); string id = $"GovUk_{propertyName}"; if (labelOptions != null) { labelOptions.For = id; } var textInputViewModel = new TextInputViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, Value = currentValue, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions, Classes = classes, TextInputAppendix = textInputAppendix, Type = type, Attributes = new Dictionary <string, string> { { "autocomplete", autocomplete } } }; if (model.HasErrorFor(property)) { textInputViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) }; } return(htmlHelper.Partial("/GovUkDesignSystemComponents/TextInput.cshtml", textInputViewModel)); }
internal static IHtmlContent GenerateHtml <TModel>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, string> > propertyLambdaExpression, int?rows = null, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null ) where TModel : GovUkViewModel { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); ThrowIfPropertyDoesNotHaveCharacterCountAttribute(property); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; string currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); string id = $"GovUk_{propertyName}"; if (labelOptions != null) { labelOptions.For = id; } int maximumCharacters = GetMaximumCharacters(property); var characterCountViewModel = new CharacterCountViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, MaxLength = maximumCharacters, Value = currentValue, Rows = rows, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions }; if (model.HasErrorFor(property)) { characterCountViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) }; } return(htmlHelper.Partial("/GovUkDesignSystemComponents/CharacterCount.cshtml", characterCountViewModel)); }
internal static IHtmlContent GenerateHtml <TModel, TProperty>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null, TextInputAppendixViewModel textInputAppendix = null ) where TModel : GovUkViewModel { var property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); var propertyName = property.Name; var model = htmlHelper.ViewData.Model; var id = $"GovUk_{propertyName}"; var currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); if (labelOptions != null) { labelOptions.For = id; } var textInputViewModel = new TextInputViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, Value = currentValue, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions, Classes = classes, TextInputAppendix = textInputAppendix }; if (model.HasErrorFor(property)) { textInputViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) } } ; return(htmlHelper.Partial("~/Partials/TextInput.cshtml", textInputViewModel)); } }
public static IHtmlContent GovUkCharacterCountFor <TModel>( this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, string> > propertyLambdaExpression, int?rows = null, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null) where TModel : GovUkViewModel { return(CharacterCountHtmlGenerator.GenerateHtml( htmlHelper, propertyLambdaExpression, rows, labelOptions, hintOptions, formGroupOptions)); }
public static async Task <IHtmlContent> GovUkFileUploadFor <TModel>( this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, IFormFile> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null) where TModel : GovUkViewModel { return(await FileUploadHtmlGenerator.GenerateHtml( htmlHelper, propertyLambdaExpression, labelOptions, hintOptions, formGroupOptions, classes)); }
public async Task <IActionResult> Create(FormGroupViewModel model) { var groupDTO = _formService.MapGroupVMToGroupDTO(model); await _formService.CreateGroup(groupDTO); _formService.Validate(ModelState); if (ModelState.IsValid) { TempData.Put("Toast", new Toast(ToastType.Success, string.Format(_stringLocalizer["Successfully created group {0}"], model.GroupName))); return(RedirectToAction(nameof(Index))); } else { return(View(model)); } }
internal static IHtmlContent GenerateHtml <TModel>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, string> > propertyLambdaExpression, int?rows = null, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null ) where TModel : GovUkViewModel { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; string currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); string id = $"GovUk_{propertyName}"; if (labelOptions != null) { labelOptions.For = id; } var textAreaViewModel = new TextAreaViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, Value = currentValue, Rows = rows, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions }; if (model.HasErrorFor(property)) { textAreaViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) }; } return(htmlHelper.Partial("/GovUkDesignSystemComponents/Textarea.cshtml", textAreaViewModel)); }
public static IHtmlContent GovUkTextInputFor <TModel>( this IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, int?> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null, TextInputAppendixViewModel textInputAppendix = null) where TModel : GovUkViewModel { return(TextInputHtmlGenerator.GenerateHtml( htmlHelper, propertyLambdaExpression, labelOptions, hintOptions, formGroupOptions, classes, textInputAppendix)); }
internal static async Task <IHtmlContent> GenerateHtml <TModel, TProperty>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > propertyLambdaExpression, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null, string classes = null) where TModel : GovUkViewModel { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; string id = propertyName; if (labelOptions != null) { labelOptions.For = id; } var fileUploadViewModel = new FileUploadViewModel { Id = id, Name = propertyName, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions, Classes = classes }; if (model.HasErrorFor(property)) { fileUploadViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) }; } return(await htmlHelper.PartialAsync("/GovUkDesignSystemComponents/FileUpload.cshtml", fileUploadViewModel)); }
private void OnGroupSelected(object sender, FormGroupViewModel e) { FormRowSelectorViewModel.FormGroup = e; }