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


C# ValidationContext.AddError方法代码示例

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


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

示例1: Validate

        public void Validate(ValidationContext context)
        {
            if (string.IsNullOrWhiteSpace(this.EmailAddress) || this.EmailAddress.IndexOf('@') < 1)
            {
                context.AddError(nameof(this.EmailAddress), "Invalid email address.");
            }

            if (string.IsNullOrWhiteSpace(this.Password) || this.Password.Length < 8)
            {
                context.AddError(nameof(this.Password), "The password must be at least 8 characters long.");
            }
        }
开发者ID:sluu99,项目名称:autorespondtext,代码行数:12,代码来源:LoginViewModel.cs

示例2: Register

        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            var timeout = this.GetTimeoutToken();

            var validationContext = new ValidationContext();
            model.Validate(validationContext);
            if (validationContext.HasErrors)
            {
                this.AddModelStateError(validationContext);
                return await this.View(model, timeout);
            }

            var account = new Account
            {
                IdentityType = IdentityType.EmailAddress,
                IdentityValue = model.EmailAddress.Trim().ToLowerInvariant(),
                CreationTime = Clock.UtcNow,
                Name = model.Name.Trim(),
                PasswordHash = BCrypt.Net.BCrypt.HashPassword(model.Password),
            };

            try
            {
                await this.accountStore.Insert(account, this.GetTimeoutToken());
                await this.CreateNewSession(account, false, timeout);
                return this.RedirectToAction("Index", "Home");
            }
            catch (DuplicateKeyException)
            {
                validationContext.AddError(nameof(model.EmailAddress), "This email address is already in use.");
                this.AddModelStateError(validationContext);
                return await this.View(model, timeout);
            }
        }
开发者ID:sluu99,项目名称:autorespondtext,代码行数:34,代码来源:AccountsController.cs

示例3: AddMemberNameToHashSet

        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal<string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            IEdmSchemaElement schemaElement = item as IEdmSchemaElement;
            string name = (schemaElement != null) ? schemaElement.FullName() : item.Name;
            if (!memberNameList.Add(name))
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }

                return false;
            }

            return true;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:ValidationHelper.cs

示例4: Login

        public async Task<ActionResult> Login(LoginViewModel model)
        {
            var timeout = this.GetTimeoutToken();

            var validationContext = new ValidationContext();
            model.Validate(validationContext);
            if (validationContext.HasErrors)
            {
                this.AddModelStateError(validationContext);
                return await this.View(model, timeout);
            }

            var account = new Account
            {
                IdentityType = IdentityType.EmailAddress,
                IdentityValue = model.EmailAddress.Trim().ToLowerInvariant(),
            };

            account = await this.accountStore.Get(account.PartitionKey, account.RowKey, timeout);
            if (account == null || BCrypt.Net.BCrypt.Verify(model.Password, account.PasswordHash) == false)
            {
                validationContext.AddError("Cannot find a matching account and password. Please try again!");
                this.AddModelStateError(validationContext);
                return await this.View(model, timeout);
            }

            await this.CreateNewSession(account, model.RememberMe, timeout);
            return this.RedirectToAction("Index", "Home");
        }
开发者ID:sluu99,项目名称:autorespondtext,代码行数:29,代码来源:AccountsController.cs


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