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


C# ValidationErrors.All方法代码示例

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


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

示例1: BraintreeApiException

 /// <summary>
 /// Initializes a new instance of the <see cref="BraintreeApiException"/> class.
 /// </summary>
 /// <param name="validationErrors">
 /// The validation errors.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 public BraintreeApiException(ValidationErrors validationErrors, string message)
     : base(string.Format("{0} {1} {2}", message, System.Environment.NewLine, string.Join(" ", validationErrors.All().Select(x => x.Message))))
 {
 }
开发者ID:jlarc,项目名称:Merchello,代码行数:13,代码来源:BraintreeApiException.cs

示例2: All_ReturnsValidationErrorsAtOneLevel

        public void All_ReturnsValidationErrorsAtOneLevel()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            builder.Append("<api-error-response>");
            builder.Append("  <errors>");
            builder.Append("    <customer>");
            builder.Append("      <errors type=\"array\">");
            builder.Append("        <error>");
            builder.Append("          <code>81608</code>");
            builder.Append("          <message>First name is too long.</message>");
            builder.Append("          <attribute type=\"symbol\">first_name</attribute>");
            builder.Append("        </error>");
            builder.Append("      </errors>");
            builder.Append("      <credit-card>");
            builder.Append("        <errors type=\"array\">");
            builder.Append("          <error>");
            builder.Append("            <code>81715</code>");
            builder.Append("            <message>Credit card number is invalid.</message>");
            builder.Append("            <attribute type=\"symbol\">number</attribute>");
            builder.Append("          </error>");
            builder.Append("          <error>");
            builder.Append("            <code>81710</code>");
            builder.Append("            <message>Expiration date is invalid.</message>");
            builder.Append("            <attribute type=\"symbol\">expiration_date</attribute>");
            builder.Append("          </error>");
            builder.Append("        </errors>");
            builder.Append("      </credit-card>");
            builder.Append("    </customer>");
            builder.Append("    <errors type=\"array\"/>");
            builder.Append("  </errors>");
            builder.Append("</api-error-response>");

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(builder.ToString());
            ValidationErrors errors = new ValidationErrors(new NodeWrapper(doc.ChildNodes[1]));

            Assert.AreEqual(0, errors.All().Count);

            Assert.AreEqual(1, errors.ForObject("customer").All().Count);
            Assert.AreEqual("first_name", errors.ForObject("customer").All()[0].Attribute);
            Assert.AreEqual(ValidationErrorCode.CUSTOMER_FIRST_NAME_IS_TOO_LONG, errors.ForObject("customer").All()[0].Code);

            Assert.AreEqual(2, errors.ForObject("customer").ForObject("credit-card").All().Count);
            Assert.AreEqual("number", errors.ForObject("customer").ForObject("credit-card").All()[0].Attribute);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_NUMBER_IS_INVALID, errors.ForObject("customer").ForObject("credit-card").All()[0].Code);

            Assert.AreEqual("expiration_date", errors.ForObject("customer").ForObject("credit-card").All()[1].Attribute);
            Assert.AreEqual(ValidationErrorCode.CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, errors.ForObject("customer").ForObject("credit-card").All()[1].Code);
        }
开发者ID:braintree,项目名称:braintree_dotnet,代码行数:50,代码来源:ValidationErrorsTest.cs

示例3: Register

        public ActionResult Register(RegisterViewModel model)
        {
            SuggestionRes response = new SuggestionRes();

            #region 各种校验

            if (string.IsNullOrWhiteSpace(model.BiaoShi))
            {//标识是否存在
                response.errorCode = 11;
                return Json(response);
            }
            var vali = Validator.IsPassword(model.Password);
            if (vali != 0)
            {//标识是否存在
                response.errorCode = vali;
                return Json(response);
            }

            if (model.Password != model.ConfirmPassword)
            {
                response.errorCode = 9;
                return Json(response);
            }
            if (string.IsNullOrWhiteSpace(model.UserName))
            {
                response.errorCode = 20;
                return Json(response);
            }
            if (model.UserName.Length > 50)
            {
                response.errorCode = 21;
                return Json(response);
            }
            if (!Validator.IsMobile(model.UserName))
            {
                response.errorCode = 22;
                return Json(response);
            }


            #endregion

            Langben.IBLL.IHuiYuanBLL m_BLL = new HuiYuanBLL();

            if (m_BLL.IsPhone(model.UserName, model.BiaoShi))
            {
                response.errorCode = 23;
                return Json(response);
            }
            ValidationErrors validationErrors = new ValidationErrors();

            HuiYuan entity = new HuiYuan()
            {
                Password = model.Password
                ,
                PhoneNumber = model.UserName
                ,
                CreateTime = DateTime.Now
                ,
                BiaoShi = model.BiaoShi
                ,
                State = "未审核"
                ,
                LogonIP = Common.IP.GetIP()
                

            };
            entity.Id = Result.GetNewId();
            string returnValue = string.Empty;
            if (m_BLL.Create(ref validationErrors, entity))
            {
                response.errorCode = 0;
                return Json(response);
            }
            else
            {
                if (validationErrors != null && validationErrors.Count > 0)
                {
                    validationErrors.All(a =>
                    {
                        returnValue += a.ErrorMessage;
                        return true;
                    });
                }
                //LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",注册的信息," + returnValue, "注册"
                //      );//写入日志   
                response.errorCode = 99;
                return Json(response);         //提示插入失败
            }


        }
开发者ID:Langbencom,项目名称:WeiXiu,代码行数:92,代码来源:AccountController.cs


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