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


C# ValidationResult.AddError方法代码示例

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


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

示例1: AccessCode

        internal IValidationResult AccessCode(AccessCode accessCode)
        {
            IValidationResult validationResult = new ValidationResult();

            // Do not permit site admins to be added.
            if (accessCode.Role == Role.SiteAdmin)
            {
                validationResult.AddError("Role.Type", "A SiteAdmin may not be added.");
            }

            // Null checks.
            if (accessCode.Description == string.Empty || accessCode.Description == null)
            {
                validationResult.AddError("Description.Null", "Description can not be empty or null.");
            }
            else
            {
                // Range checks.
                if (accessCode.Description.Length > 30)
                {
                    validationResult.AddError("Description.Length", "Description should be less than 30 characters in length.");
                }
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:26,代码来源:AccountCheck.cs

示例2: Account

        internal IValidationResult Account(Account account)
        {
            IValidationResult validationResult = new ValidationResult();

            var subscriptionPlan = this.doctrineShipsRepository.GetSubscriptionPlan(account.SubscriptionPlanId);

            // Null checks.
            if (account.Description == string.Empty || account.Description == null)
            {
                validationResult.AddError("Description.Null", "Description can not be empty or null.");
            }
            else
            {
                // Range checks.
                if (account.Description.Length > 30)
                {
                    validationResult.AddError("Description.Length", "Description should be less than 30 characters in length.");
                }
            }

            // Does the subscription plan exist in the database?
            if (subscriptionPlan == null)
            {
                validationResult.AddError("SubscriptionPlan.Null", "The subscription plan does not exist in the database.");
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:28,代码来源:AccountCheck.cs

示例3: Evaluate

        /// <summary>
        /// Evaluates the rule for the given request.  The <b>RegexRule</b> applies its
        /// regular expression pattern to its specified field in the given request.
        /// </summary>
        /// <param name="request">The <b>MvcRequest</b> to evaluate the rule for.</param>
        /// <returns>A <b>ValidationResult</b> indicating the result of evaluating the
        ///			rule and any validation errors that occurred.</returns>
        public override ValidationResult Evaluate(
            MvcRequest request)
        {
            ValidationResult result = new ValidationResult {
                Passed = false
            };

            string fieldVal = request[Field.EvaluatePropertyValue()];
            // TODO: what if fieldVal is null??  is it valid or not??

            //  if the field value is null and the check is not explicitly for null,
            //  add the error
            if (fieldVal == null) {
                if (this.Pattern == NULL_PATTERN) {
                    result.Passed = true;
                } else {
                    result.AddError(Field, ErrorId);
                }
            } else {
                bool passed = Regex.IsMatch(fieldVal, this.Pattern);

                if (passed) {
                    result.Passed = true;
                } else {
                    result.AddError(Field, ErrorId);
                }
            }

            return result;
        }
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:37,代码来源:RegexRule.cs

示例4: ApiKey

        internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo)
        {
            IValidationResult validationResult = new ValidationResult();

            // Define the bitwise masks for both character and corporation api keys.
            const int charContractMask = 67108864;
            const int corpContractMask = 8388608;
            int checkResult = 0;

            // Perform a bitwise AND to determine if contract access is available on the api key.
            if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account)
            {
                checkResult = apiKeyInfo.AccessMask & charContractMask;

                if (checkResult == 0)
                {
                    validationResult.AddError("ApiKey.AccessMask", "A character api key must have 'Contracts' access enabled.");
                }
            }
            else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation)
            {
                checkResult = apiKeyInfo.AccessMask & corpContractMask;

                if (checkResult == 0)
                {
                    validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have 'Contracts' access enabled.");
                }
            }

            return validationResult;
        }
开发者ID:jameswlong,项目名称:doctrineships,代码行数:31,代码来源:SalesAgentCheck.cs

示例5: ShipFit

        internal IValidationResult ShipFit(ShipFit shipFit)
        {
            IValidationResult validationResult = new ValidationResult();

            // Check that the ship fit has a valid account id.
            if (shipFit.AccountId < 0 || shipFit.AccountId > int.MaxValue)
            {
                validationResult.AddError("AccountId.Range_" + shipFit.ShipFitId.ToString(), "AccountId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the int data type.");
            }

            // Null checks.
            if (shipFit.Notes == null)
            {
                validationResult.AddError("Notes.Null", "Notes cannot be null.");
            }

            if (shipFit.Name == null)
            {
                validationResult.AddError("Name.Null", "Name cannot be null.");
            }

            if (shipFit.Role == null)
            {
                validationResult.AddError("Role.Null", "Role cannot be null.");
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:28,代码来源:ShipFitCheck.cs

示例6: When_passed_multiple_errors_Should_aggregate_the_error_messages

 public void When_passed_multiple_errors_Should_aggregate_the_error_messages()
 {
     var result = new ValidationResult();
     result.AddError<object>(o => o.GetType(), "foo");
     result.AddError<object>(o => o.GetType(), "bar");
     result.GetAllErrors().Count.ShouldEqual(1);
 }
开发者ID:shawnewallace,项目名称:Griz,代码行数:7,代码来源:ValidationResultTester.cs

示例7: Should_process_messages

 public void Should_process_messages()
 {
     var result = new ValidationResult();
     result.AddError<object>(x => x.ToString(), "Message");
     result.AddError<object>(x => x.ToString(), "Another");
     result.GetErrors<object>(x => x.ToString()).ShouldContain("Message");
     result.GetErrors<object>(x => x.ToString()).ShouldContain("Another");
 }
开发者ID:shawnewallace,项目名称:Griz,代码行数:8,代码来源:ValidationResultTester.cs

示例8: Format_SeveralErrorsWithSameMessageButDifferentTarges_OutputsOnlyOneMessage

		public void Format_SeveralErrorsWithSameMessageButDifferentTarges_OutputsOnlyOneMessage()
		{
			// ARRANGE
			var validationResult = new ValidationResult();
			validationResult.AddError("target1", "Error1");
			validationResult.AddError("target2", validationResult.ErrorList[0].ErrorText);

			var formatter = new NumberedListValidationResultFormatter();
			var expectedFormattedString = validationResult.ErrorList[0].ErrorText;

			// ACT
			var actualFormattedString = formatter.Format(validationResult);

			// VERIFY
			Assert.Equal(expectedFormattedString, actualFormattedString);
		}
开发者ID:ruisebastiao,项目名称:mvvmvalidation,代码行数:16,代码来源:NumberedListValidationResultFormatterTests.cs

示例9: SalesAgent

        internal IValidationResult SalesAgent(SalesAgent salesAgent)
        {
            IValidationResult validationResult = new ValidationResult();

            // Is the salesAgent id valid?
            if (salesAgent.SalesAgentId <= 0 || salesAgent.SalesAgentId > int.MaxValue)
            {
                validationResult.AddError("SalesAgentId.Range", "SalesAgentId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the int data type.");
            }

            // Does the salesAgent already exist in the database?
            if (this.doctrineShipsRepository.GetSalesAgent(salesAgent.SalesAgentId) != null)
            {
                validationResult.AddError("SalesAgentId.Exists", "SalesAgentId already exists in the database.");
            }

            return validationResult;
        }
开发者ID:jameswlong,项目名称:doctrineships,代码行数:18,代码来源:SalesAgentCheck.cs

示例10: Component

        internal IValidationResult Component(Component component)
        {
            IValidationResult validationResult = new ValidationResult();

            // Is the component id valid?
            if (component.ComponentId <= 0 || component.ComponentId > int.MaxValue)
            {
                validationResult.AddError("ComponentId.Range_" + component.ComponentId.ToString(), "ComponentId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the int data type.");
            }

            // Does the component already exist in the database?
            if (this.doctrineShipsRepository.GetComponent(component.ComponentId) != null)
            {
                validationResult.AddError("ComponentId.Exists_" + component.ComponentId.ToString(), "ComponentId already exists in the database.");
            }

            return validationResult;
        }
开发者ID:jameswlong,项目名称:doctrineships,代码行数:18,代码来源:ShipFitCheck.cs

示例11: ShipFitComponent

        internal IValidationResult ShipFitComponent(ShipFitComponent shipFitComponent)
        {
            IValidationResult validationResult = new ValidationResult();

            // Check that the ship fit component has a valid quantity.
            if (shipFitComponent.Quantity <= 0 || shipFitComponent.Quantity > long.MaxValue)
            {
                validationResult.AddError("Quantity.Range_" + shipFitComponent.ShipFitComponentId.ToString(), "Quantity can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the long data type.");
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:12,代码来源:ShipFitCheck.cs

示例12: ApiKey

        internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo)
        {
            IValidationResult validationResult = new ValidationResult();

            // Check the access mask of the key is correct.
            if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account)
            {
                if (apiKeyInfo.AccessMask != 67108864)
                {
                    validationResult.AddError("ApiKey.AccessMask", "A character api key must have an access mask of 67108864 ('Contracts' Only).");
                }
            }
            else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation)
            {
                if (apiKeyInfo.AccessMask != 8388608)
                {
                    validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have an access mask of 8388608 ('Contracts' Only).");
                }
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:22,代码来源:SalesAgentCheck.cs

示例13: Contract

        internal IValidationResult Contract(Contract contract)
        {
            IValidationResult validationResult = new ValidationResult();

            // Is the contract id valid?
            if (contract.ContractId <= 0 || contract.ContractId > long.MaxValue)
            {
                validationResult.AddError("ContractId.Range", "ContractId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the long data type.");
            }

            // Does the contract already exist in the database?
            if (this.doctrineShipsRepository.GetContract(contract.ContractId) != null)
            {
                validationResult.AddError("ContractId.Exists", "ContractId already exists in the database.");
            }

            // Does the ship fit exist in the database?
            if (this.doctrineShipsRepository.GetShipFit(contract.ShipFitId) == null)
            {
               validationResult.AddError("ShipFitId.Exists", "ShipFitId does not exist in the database.");
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:24,代码来源:ContractCheck.cs

示例14: Customer

        internal IValidationResult Customer(Customer customer)
        {
            IValidationResult validationResult = new ValidationResult();

            // Is the customer id valid?
            if (customer.CustomerId <= 0 || customer.CustomerId > int.MaxValue)
            {
                validationResult.AddError("CustomerId.Range", "CustomerId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the long data type.");
            }

            // Is the customer name valid?
            if (customer.Name == string.Empty || customer.Name == null)
            {
                validationResult.AddError("CustomerName.Null", "CustomerName can not be empty or null.");
            }

            // Does the customer already exist in the database?
            if (this.doctrineShipsRepository.GetCustomer(customer.CustomerId) != null)
            {
                validationResult.AddError("CustomerId.Exists", "CustomerId already exists in the database.");
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:24,代码来源:CustomerCheck.cs

示例15: Evaluate

        /// <summary>
        /// Evaluates the rule for the given request.  The <b>OrRule</b> short circuits
        /// on the first successful child rule, with a passed status.
        /// </summary>
        /// <param name="request">The <b>MvcRequest</b> to evaluate the rule for.</param>
        /// <returns>A <b>ValidationResult</b> indicating the result of evaluating the
        ///			rule and any validation errors that occurred.</returns>
        public override ValidationResult Evaluate(
            MvcRequest request)
        {
            ValidationResult result = new ValidationResult { Passed = false };

            // TODO: if cnt is 0 should we return true or false??
            int cnt = children.Count;
            for (int k = 0; k < cnt && !result.Passed; k++) {
                IValidationRule rule = children[k];
                        //  evaluate the child rule
                ValidationResult childResult = rule.Evaluate(request);
                        //  clear out any previous validation errors
                result.ClearErrors();
                        //  if the child rule passed, set this rule to passed,
                        //  if not, add the errors from the child to the OrRule's result
                if (childResult.Passed) {
                    result.Passed = true;
                } else {
                    result.AddErrors(childResult.Errors);

                    if (rule.StopOnFail || childResult.StopProcessing) {
                        result.StopProcessing = true;
                        break;
                    }
                }
            }

                    //  if the OrRule did not pass and the is a specific error identified
                    //  for the OrRule, replace any errors from the children with the one
                    //  for the OrRule
            if (!result.Passed && (ErrorId != 0)) {
                result.ClearErrors();
                result.AddError(Field, ErrorId);
            }

            return result;
        }
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:44,代码来源:OrRule.cs


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