Пример #1
0
 /// <summary>
 /// 创建一个规则
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个规则</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, Rule entity)
 {
     try
     {
         repository.Create(entity);
         return(true);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
Пример #2
0
        public async Task <ActionResult> UpdateRule([FromBody] Rule rule)
        {
            if (rule.Id == default(int))
            {
                var existRule = await ruleRepository.Get(1);

                if (existRule == null)
                {
                    await ruleRepository.Create(rule);

                    return(Ok(new { status = ResultStatus.STATUS_OK, data = rule }));
                }
                else
                {
                    rule.Id = 1;
                    if (rule.MaxAge != default(int))
                    {
                        existRule.MaxAge = rule.MaxAge;
                    }
                    if (rule.MinAge != default(int))
                    {
                        existRule.MinAge = rule.MinAge;
                    }
                    if (rule.MaxSize != default(int))
                    {
                        existRule.MaxSize = rule.MaxSize;
                    }
                    if (rule.MinSize != default(int))
                    {
                        existRule.MinSize = rule.MinSize;
                    }
                    if (rule.MaxPoint != default(int))
                    {
                        existRule.MaxPoint = rule.MaxPoint;
                    }
                    if (rule.SchoolName != default(string))
                    {
                        existRule.SchoolName = rule.SchoolName;
                    }
                    if (rule.SchoolAddress != default(string))
                    {
                        existRule.SchoolAddress = rule.SchoolAddress;
                    }
                    await ruleRepository.Update(1, rule);

                    return(Ok(new { status = ResultStatus.STATUS_OK, data = rule }));
                }
            }
            else
            {
                var existRule = await ruleRepository.Get(rule.Id);

                if (existRule != null)
                {
                    if (rule.MaxAge != default(int))
                    {
                        existRule.MaxAge = rule.MaxAge;
                    }
                    if (rule.MinAge != default(int))
                    {
                        existRule.MinAge = rule.MinAge;
                    }
                    if (rule.MaxSize != default(int))
                    {
                        existRule.MaxSize = rule.MaxSize;
                    }
                    if (rule.MinSize != default(int))
                    {
                        existRule.MinSize = rule.MinSize;
                    }
                    if (rule.MaxPoint != default(int))
                    {
                        existRule.MaxPoint = rule.MaxPoint;
                    }
                    if (rule.SchoolName != default(string))
                    {
                        existRule.SchoolName = rule.SchoolName;
                    }
                    if (rule.SchoolAddress != default(string))
                    {
                        existRule.SchoolAddress = rule.SchoolAddress;
                    }
                    await ruleRepository.Update(rule.Id, rule);

                    return(Ok(new { status = ResultStatus.STATUS_OK, data = rule }));
                }
                else
                {
                    return(Ok(new { status = ResultStatus.STATUS_NOT_FOUND, message = "Không tìm thấy quy định" }));
                }
            }
        }