当前位置: 首页>>代码示例>>C#>>正文


C# IUpdateModel.AddModelError方法代码示例

本文整理汇总了C#中IUpdateModel.AddModelError方法的典型用法代码示例。如果您正苦于以下问题:C# IUpdateModel.AddModelError方法的具体用法?C# IUpdateModel.AddModelError怎么用?C# IUpdateModel.AddModelError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUpdateModel的用法示例。


在下文中一共展示了IUpdateModel.AddModelError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PartFieldEditorUpdate

        public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartFieldDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (!builder.FieldType.Equals(typeof(MoneyField).Name)) yield break;

            var model = new MoneyFieldSettings();

            if (updateModel.TryUpdateModel(model, typeof(MoneyFieldSettings).Name, null, null))
            {
                if (string.IsNullOrEmpty(model.DefaultCurrency))
                {
                    builder.WithSetting("MoneyFieldSettings.DefaultCurrency", Currency.FromCurrentCulture().Iso3LetterCode);
                }
                else
                {
                    Currency parsedCurrency;
                    if (Currency.TryParse(model.DefaultCurrency, out parsedCurrency))
                    {
                        builder.WithSetting("MoneyFieldSettings.DefaultCurrency", model.DefaultCurrency);
                    }
                    else
                    {
                        updateModel.AddModelError("InvalidCurrencyIsoCode", T("MoneyField - Invalid currency iso code was given."));
                    }
                }

                builder.WithSetting("MoneyFieldSettings.IsCurrencyReadOnly", model.IsCurrencyReadOnly.ToString(CultureInfo.InvariantCulture));
                builder.WithSetting("MoneyFieldSettings.Hint", model.Hint);
                builder.WithSetting("MoneyFieldSettings.Required", model.Required.ToString(CultureInfo.InvariantCulture));
            }
            yield return DefinitionTemplate(model);
        }
开发者ID:SmartFire,项目名称:Lombiq-Fields,代码行数:31,代码来源:MoneyFieldEditorEvents.cs

示例2: PartFieldEditorUpdate

        public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartFieldDefinitionBuilder builder, IUpdateModel updateModel) {
            if (builder.FieldType != "ReferenceField") {
                yield break;
            }
            var model = new ReferenceFieldSettings();
            if (updateModel.TryUpdateModel(model, "ReferenceFieldSettings", null, null)) {
                UpdateSettings(model, builder, "ReferenceFieldSettings");

                if (model.QueryId <= 0) {
                    model.QueryId = CreateQuery(model.ContentTypeName.ToString(CultureInfo.InvariantCulture));
                }

                if (model.RelationshipId <= 0) {
                    var httpContext = _httpContextAccessor.Current();
                    var routeValues = httpContext.Request.RequestContext.RouteData.Values;
                    var entityName = routeValues["id"].ToString();
                    model.RelationshipId = _relationshipService.CreateOneToManyRelationship(builder.Name, model.RelationshipName, model.ContentTypeName, entityName);
                }

                if (model.QueryId <= 0 || model.RelationshipId <= 0) {
                    updateModel.AddModelError("QueryOrRelation", T("Invalid Query or Relationship Id"));
                    yield break;
                }

                UpdateSettings(model, builder, "ReferenceFieldSettings");
                builder.WithSetting("ReferenceFieldSettings.DisplayAsLink", model.DisplayAsLink.ToString(CultureInfo.InvariantCulture));
                builder.WithSetting("ReferenceFieldSettings.ContentTypeName", model.ContentTypeName.ToString(CultureInfo.InvariantCulture));
                builder.WithSetting("ReferenceFieldSettings.RelationshipName", model.RelationshipName.ToString(CultureInfo.InvariantCulture));
                builder.WithSetting("ReferenceFieldSettings.RelationshipId", model.RelationshipId.ToString(CultureInfo.InvariantCulture));
                builder.WithSetting("ReferenceFieldSettings.QueryId", model.QueryId.ToString(CultureInfo.InvariantCulture));
            }
            yield return DefinitionTemplate(model);
        }
开发者ID:jgtaveras,项目名称:Coevery,代码行数:33,代码来源:ReferenceFieldEditorEvents.cs

示例3: UpdateFieldSettings

 public override void UpdateFieldSettings(string fieldType, string fieldName, SettingsDictionary settingsDictionary, IUpdateModel updateModel) {
     if (fieldType != "OptionSetField") {
         return;
     }
     var model = new OptionSetFieldSettings();
     if (updateModel.TryUpdateModel(model, "OptionSetFieldSettings", null, null)) {
         UpdateSettings(model, settingsDictionary, "OptionSetFieldSettings");
         if (model.OptionSetId == 0) {
             model.OptionSetId = CreateOptionSetPart(fieldName, model);
             if (model.OptionSetId <= 0) {
                 updateModel.AddModelError("OptionSet", T("No items inputted"));
                 return;
             }
         }
         settingsDictionary["OptionSetFieldSettings.OptionSetId"] = model.OptionSetId.ToString("D");
         settingsDictionary["OptionSetFieldSettings.ListMode"] = model.ListMode.ToString();
     }
 }
开发者ID:wezmag,项目名称:Coevery,代码行数:18,代码来源:OptionSetFieldEditorEvents.cs

示例4: PartFieldEditorUpdate

        public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartFieldDefinitionBuilder builder, IUpdateModel updateModel) {
            if (builder.FieldType != "OptionSetField") {
                yield break;
            }

            var model = new OptionSetFieldSettings();

            if (updateModel.TryUpdateModel(model, "OptionSetFieldSettings", null, null)) {
                UpdateSettings(model, builder, "OptionSetFieldSettings");

                if (model.OptionSetId == 0) {
                    string[] options = (!String.IsNullOrWhiteSpace(model.Options)) ?
                        model.Options.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) : null;

                    if (options == null) {
                        updateModel.AddModelError("OptionSet",T("No items inputted"));
                        yield break;
                    }

                    var optionSetPart = _contentManager.New<OptionSetPart>("OptionSet");
                    optionSetPart.As<TitlePart>().Title = builder.Name;

                    _contentManager.Create(optionSetPart, VersionOptions.Published);

                    foreach (var option in options) {
                        var term = _contentManager.New<OptionItemPart>("OptionItem");
                        term.OptionSetId = optionSetPart.Id;
                        term.Name = option;
                        _contentManager.Create(term, VersionOptions.Published);
                    }
                    model.OptionSetId = optionSetPart.Id;
                }

                builder
                    .WithSetting("OptionSetFieldSettings.OptionSetId", model.OptionSetId.ToString())
                    .WithSetting("OptionSetFieldSettings.ListMode", model.ListMode.ToString());
            }

            yield return DefinitionTemplate(model);
        }
开发者ID:jgtaveras,项目名称:Coevery,代码行数:40,代码来源:OptionSetFieldEditorEvents.cs

示例5: UpdateEditor

        public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater)
        {
            var builderSteps = _recipeBuilderSteps.OrderBy(x => x.Position).Select(x => new ExportStepViewModel {
                Name = x.Name,
                DisplayName = x.DisplayName,
                Description = x.Description,
                Editor = x.BuildEditor(shapeFactory),
                IsVisible = x.IsVisible
            });

            var viewModel = new RecipeBuilderViewModel {
                Steps = builderSteps.ToList()
            };

            if (updater != null) {
                if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
                    if (viewModel.UploadConfigurationFile) {
                        var configurationFile = _orchardServices.WorkContext.HttpContext.Request.Files["ConfigurationFile"];

                        if (configurationFile.ContentLength == 0)
                            updater.AddModelError("ConfigurationFile", T("No configuration file was specified."));
                        else {
                            var configurationDocument = XDocument.Parse(new StreamReader(configurationFile.InputStream).ReadToEnd());
                            Configure(new ExportActionConfigurationContext(configurationDocument.Root.Element(Name)));
                        }
                    }
                    else {
                        var exportStepNames = viewModel.Steps.Where(x => x.IsSelected).Select(x => x.Name);
                        var stepsQuery = from name in exportStepNames
                            let provider = _recipeBuilderSteps.SingleOrDefault(x => x.Name == name)
                            where provider != null
                            select provider;
                        var steps = stepsQuery.ToArray();
                        var stepUpdater = new Updater(updater, secondHalf => String.Format("{0}.{1}", Prefix, secondHalf));
                        foreach (var exportStep in steps) {
                            exportStep.UpdateEditor(shapeFactory, stepUpdater);
                        }

                        RecipeBuilderSteps = steps;
                    }
                }
            }

            return shapeFactory.EditorTemplate(TemplateName: "ExportActions/BuildRecipe", Model: viewModel, Prefix: Prefix);
        }
开发者ID:yanghl22,项目名称:Orchard,代码行数:45,代码来源:BuildRecipeAction.cs

示例6: PopulateAddressFromViewModel

        public bool PopulateAddressFromViewModel(AddressPart part, ViewModels.AddressEditViewModel viewModel, IUpdateModel updater, string prefix)
        {
            var ok = true;

            // Copy normal fields from view model
            if (String.IsNullOrWhiteSpace(viewModel.PostalCode))
            {
                updater.AddModelError(prefix + ".PostalCode", T("Please enter a post code."));
                ok = false;
            }
            else
            {
                // Strip any spaces
                part.PostalCode = viewModel.PostalCode = viewModel.PostalCode.Replace(" ", "");
            }
 
            part.AddressType = viewModel.AddressType;
            if (String.IsNullOrWhiteSpace(viewModel.Address1))
            {
                updater.AddModelError(prefix + ".Address1", T("Please enter at least the first line of the street address."));
                ok = false;
            }
            part.Address1 = viewModel.Address1;
            part.Address2 = viewModel.Address2;
            part.Address3 = viewModel.Address3;

            // Attempt to create inputted country name
            if (!String.IsNullOrWhiteSpace(viewModel.CountryName))
            {
                try
                {
                    var country = GetOrCreateCountryByName(viewModel.CountryName);
                    if (country != null)
                    {
                        viewModel.CountryId = country.Id;
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Couldn't create country");
                }
            }
            // Attempt to create inputted region name
            if (!viewModel.CountryId.HasValue)
            {
                updater.AddModelError(prefix + ".CountryName", T("Error saving country. Enter a valid country name or select from the list."));
                ok = false;
            }
            if (viewModel.CountryId.HasValue && !String.IsNullOrWhiteSpace(viewModel.TownName))
            {
                var region = GetOrCreateTownByName(viewModel.CountryId.Value, viewModel.TownName);
                if (region != null)
                {
                    viewModel.TownId = region.Id;
                }
            }
            if (!viewModel.TownId.HasValue){
                updater.AddModelError(prefix + ".TownName", T("Enter a valid town name or select from the list."));
                ok = false;
            }
            return ok;
        }
开发者ID:akhurst,项目名称:ricealumni,代码行数:62,代码来源:AddressDirectoryService.cs

示例7: CreateAddress

 public IContent CreateAddress(ViewModels.AddressEditViewModel viewModel,IUpdateModel updater, string prefix)
 {
     var address = _services.ContentManager.New(AddressesContentType);
     var part = address.As<AddressPart>();
     if (part != null)
     {
         if (PopulateAddressFromViewModel(part, viewModel, updater, prefix))
         {
             // Publish
             _services.ContentManager.Create(address);
             if (!LinkAddressToTown(part, viewModel.TownId.Value))
             {
                 updater.AddModelError(prefix + ".TownName", T("Error saving town. Enter a valid town name or select from the list."));
                 _services.ContentManager.Remove(address);
             }
             return address;
         }
     }
     return null;
 }
开发者ID:akhurst,项目名称:ricealumni,代码行数:20,代码来源:AddressDirectoryService.cs

示例8: UpdateEditor

        public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater)
        {
            var viewModel = new UploadRecipeViewModel {
                SuperUserName = _orchardServices.WorkContext.CurrentSite.SuperUser,
                RecipeExecutionSteps = _recipeExecutionSteps.Select(x => new RecipeExecutionStepViewModel {
                    Name = x.Name,
                    DisplayName = x.DisplayName,
                    Description = x.Description,
                    Editor = x.BuildEditor(shapeFactory)
                }).Where(x => x.Editor != null).ToList()
            };

            if (updater != null) {
                if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
                    // Validate and read uploaded recipe file.
                    var request = _orchardServices.WorkContext.HttpContext.Request;
                    var file = request.Files["RecipeFile"];
                    var isValid = true;

                    ResetSite = viewModel.ResetSite;
                    SuperUserPassword = viewModel.SuperUserPassword;

                    if (file == null || file.ContentLength == 0) {
                        updater.AddModelError("RecipeFile", T("No recipe file selected."));
                        isValid = false;
                    }

                    if (ResetSite) {
                        if (String.IsNullOrWhiteSpace(viewModel.SuperUserPassword)) {
                            updater.AddModelError("SuperUserPassword", T("Please specify a new password for the super user."));
                            isValid = false;
                        }
                        else if (!String.Equals(viewModel.SuperUserPassword, viewModel.SuperUserPasswordConfirmation)) {
                            updater.AddModelError("SuperUserPassword", T("The passwords do not match."));
                            isValid = false;
                        }
                    }

                    var stepUpdater = new Updater(updater, secondHalf => String.Format("{0}.{1}", Prefix, secondHalf));

                    // Update the view model with non-roundtripped values.
                    viewModel.SuperUserName = _orchardServices.WorkContext.CurrentSite.SuperUser;
                    foreach (var stepViewModel in viewModel.RecipeExecutionSteps) {
                        var step = _recipeExecutionSteps.Single(x => x.Name == stepViewModel.Name);
                        stepViewModel.DisplayName = step.DisplayName;
                        stepViewModel.Description = step.Description;

                        // Update the step with posted values.
                        stepViewModel.Editor = step.UpdateEditor(shapeFactory, stepUpdater);
                    }

                    if (isValid) {
                        // Read recipe file.
                        RecipeDocument = XDocument.Parse(new StreamReader(file.InputStream).ReadToEnd());
                    }
                }
            }

            return shapeFactory.EditorTemplate(TemplateName: "ImportActions/ExecuteRecipe", Model: viewModel, Prefix: Prefix);
        }
开发者ID:yanghl22,项目名称:Orchard,代码行数:60,代码来源:ExecuteRecipeAction.cs


注:本文中的IUpdateModel.AddModelError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。