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


C# ValidationErrors.Add方法代码示例

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


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

示例1: Create

 public bool Create(ref ValidationErrors errors, SysModuleOperateModel model)
 {
     try
     {
         SysModuleOperate entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysModuleOperate();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.KeyCode = model.KeyCode;
         entity.ModuleId = model.ModuleId;
         entity.IsValid = model.IsValid;
         entity.Sort = model.Sort;
         if (m_Rep.Create(entity) == 1)
         {
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:34,代码来源:SysModuleOperateBLL+.cs

示例2: ValidateNeedsLabels

        void ValidateNeedsLabels(Issue issue, ValidationErrors validationErrors, Repository repository)
        {
            var lastActivityOnIssue = issue.UpdatedAt; //todo: does this include comments?

            if (issue.Labels.Any(l => l.Name == "Type: Bug") && !issue.Labels.Any(l => l.Name.StartsWith("Needs:")))
            {
                if (lastActivityOnIssue < DateTime.UtcNow.AddDays(-3))
                {
                    validationErrors.Add(new ValidationError
                    {
                        Reason = "This bug doesn't seem to be triaged, use one of the `Needs: X` labels to remember what the next steps are",
                        Issue = issue,
                        Repository = repository
                    });
                }

                return;
            }

            if (issue.Labels.Any(l => l.Name == "Needs: Triage") && lastActivityOnIssue < DateTime.UtcNow.AddDays(-3))
            {
                validationErrors.Add(new ValidationError
                {
                    Reason = "Issue needs triage but hasn't been updated for 3 days",
                    Issue = issue,
                    Repository = repository
                });
            }

            if (issue.Labels.Any(l => l.Name == "Needs: Reproduction") && lastActivityOnIssue < DateTime.UtcNow.AddDays(-7))
            {
                validationErrors.Add(new ValidationError
                {
                    Reason = "Issue needs a repro but hasn't been touched in the last 7 days",
                    Issue = issue,
                    Repository = repository
                });
            }

            if (issue.Labels.Any(l => l.Name == "Needs: Scheduling") && lastActivityOnIssue < DateTime.UtcNow.AddMonths(-3))
            {
                validationErrors.Add(new ValidationError
                {
                    Reason = "Issue needs scheduling but hasn't been touched in the last 3 months",
                    Issue = issue,
                    Repository = repository
                });
            }
        }
开发者ID:adamralph,项目名称:PBot,代码行数:49,代码来源:CheckIssuesForRepository.cs

示例3: Delete

 public bool Delete(ref ValidationErrors errors, string id)
 {
     try
     {
         //检查是否有下级
         if (dbContainer.SysModules.AsQueryable().Where(a => a.SysModule2.Id == id).Count() > 0)
         {
             errors.Add("有下属关联,请先删除下属!");
             return false;
         }
         m_Rep.Delete(dbContainer, id);
         if (dbContainer.SaveChanges() > 0)
         {
             //清理无用的项
             dbContainer.P_Sys_ClearUnusedRightOperate();
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:29,代码来源:SysModuleBLL.cs

示例4: Validate

 public override void Validate(string value, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(value))
     {
         int result = int.MaxValue;
         if (!int.TryParse(value, out result))
         {
             errors.Add(Key,ErrorMessage);
         }
         else
         {
             if (result > _maxValue || result < _minValue)
                 errors.Add(Key,ErrorMessageOutOfRange);
         }
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:16,代码来源:IsIntegerInRange.cs

示例5: Validate

 public override void Validate(string value, ValidationErrors errors)
 {
     if (!IsPresent(value))
     {
         errors.Add(Key,ErrorMessage);
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:7,代码来源:RequiredValidator.cs

示例6: Create

        /// <summary>
        /// 创建一个菜单
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个菜单</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity)
        {
            int count = 1;

            foreach (string item in entity.SysOperationId.GetIdSort())
            {
                SysOperation sys = new SysOperation { Id = item };
                db.SysOperation.Attach(sys);
                entity.SysOperation.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                //创建后重置菜单编码
                List<int> flags = new List<int>();//层级
                GetMenus2(null, flags);
                db.SaveChanges();
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
开发者ID:vipsms,项目名称:right,代码行数:34,代码来源:SysMenuBLL.cs

示例7: Validate

 public override void Validate(string value, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(value))
     {
         if(value.Length > _maxLength || value.Length < _minLength)
             errors.Add(Key,ErrorMessage);
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:8,代码来源:StringLengthRangeValidator.cs

示例8: Validate

 public void Validate(string password, string salt, string hashedPassword, ValidationErrors errors)
 {
     if (RequiredValidator.IsPresent(password))//dont check salt and hashedPassword IsPresent
     {
         if (!new StringHasher().ComputedHashUsingGivenSaltMatchesGivenHash( password, salt, hashedPassword))
             errors.Add(Key, ErrorMessage);                
     }
 }
开发者ID:aregsar,项目名称:rapido,代码行数:8,代码来源:HashedValueValidator.cs

示例9: Validate

        public override void Validate(string guidstring, ValidationErrors errors)
        {
            Guid guid;

            if (!Guid.TryParse(guidstring, out guid))
            {
                errors.Add(Key, ErrorMessage);
            }
        }
开发者ID:aregsar,项目名称:rapido,代码行数:9,代码来源:GuidStringValidator.cs

示例10: Validate

        public override void Validate(string value, ValidationErrors errors)
        {
            if (RequiredValidator.IsPresent(value))
            {
                Regex regex = new Regex(_pattern);

                if (!regex.IsMatch(value.Trim()))
                    errors.Add(Key,ErrorMessage);
            }
        }
开发者ID:aregsar,项目名称:rapido,代码行数:10,代码来源:RegexValidator.cs

示例11: Create

 public bool Create(ref ValidationErrors errors, SysModuleModel model)
 {
     try
     {
         SysModule entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysModule();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.EnglishName = model.EnglishName;
         entity.ParentId = model.ParentId;
         entity.Url = model.Url;
         entity.Iconic = model.Iconic;
         entity.Sort = model.Sort;
         entity.Remark = model.Remark;
         entity.Enable = model.Enable;
         entity.CreatePerson = model.CreatePerson;
         entity.CreateTime = model.CreateTime;
         entity.IsLast = model.IsLast;
         if (m_Rep.Create(entity) == 1)
         {
             //分配给角色
             dbContainer.P_Sys_InsertSysRight();
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:42,代码来源:SysModuleBLL.cs

示例12: Create

 /// <summary>
 /// 创建一个文档评论
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个文档评论</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, SysDocumentTalk entity)
 {
     try
     {
         repository.Create(entity);
         return true;
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return false;
 }
开发者ID:vipsms,项目名称:right,代码行数:21,代码来源:SysDocumentTalkBLL.cs

示例13: Create

 public bool Create(ref ValidationErrors errors, SysRoleModel model)
 {
     try
     {
         SysRole entity = m_Rep.GetById(model.Id);
         if (entity != null)
         {
             errors.Add(Suggestion.PrimaryRepeat);
             return false;
         }
         entity = new SysRole();
         entity.Id = model.Id;
         entity.Name = model.Name;
         entity.Description = model.Description;
         entity.CreateTime = model.CreateTime;
         entity.CreatePerson = model.CreatePerson;
         if (m_Rep.Create(entity) == 1)
         {
             //分配给角色
             dbContainer.P_Sys_InsertSysRight();
             //清理无用的项
             dbContainer.P_Sys_ClearUnusedRightOperate();
             return true;
         }
         else
         {
             errors.Add(Suggestion.InsertFail);
             return false;
         }
     }
     catch (Exception ex)
     {
         errors.Add(ex.Message);
         ExceptionHander.WriteException(ex);
         return false;
     }
 }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:37,代码来源:SysRoleBLL.cs

示例14: Create

        /// <summary>
        /// 创建一个实体
        /// </summary>
        /// <param name="errors">持久的错误信息</param>
        /// <param name="model">模型</param>
        /// <returns>是否成功</returns>
        public bool Create(ref ValidationErrors errors,SysSampleModel model)
        {
            try
            {
                SysSample entity = Rep.GetById(model.ID);
                if (entity != null)
                {
                    errors.Add("主键重复");
                    return false;
                }
                entity = new SysSample();
                entity.ID = model.ID;
                entity.Name = model.Name;
                entity.Age = model.Age;
                entity.Bir = model.Bir;
                entity.Photo = model.Photo;
                entity.Note = model.Note;
                entity.CreatTime = model.CreatTime;

                if (Rep.Create(entity) == 1)
                {
                    return true;
                }
                else
                {
                    errors.Add("插入失败");
                    return false;
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return false;
            }
        }
开发者ID:WatingYou,项目名称:MvcApplication,代码行数:42,代码来源:SysSampleBLL+.cs

示例15: Validate

        public void Validate(string val, string compareVal, ValidationErrors errors)
        {
            if (RequiredValidator.IsPresent(val))//dont check compareVal IsPresent
            {
                if (!errors.ExistFor(Key))
                {
                    //only if there are no errors for val, do the compare
                    //so need to call this after running all validations of val to achieve this effect
                    if (val != compareVal)
                    {
                        errors.Add(Key,ErrorMessage);
                    }
                }
            }

        }
开发者ID:aregsar,项目名称:rapido,代码行数:16,代码来源:CompareValidator.cs


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