Example #1
0
        public async Task <IActionResult> FindAsync([FromQuery] uint id)
        {
            var result = await _dataBaseOptionService.FindAsync(id);

            return(Ok(new ResponseResult {
                Result = result
            }));
        }
        /// <summary>
        /// 根据key查询redis,不存在则查询数据库并将结果插入Redis
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ResponseResult <XXXAo> > GetOrCreateAsync(uint id)
        {
            var result = await _redisManager.GetOrSetAsync <XXXAo>($"RedisOption:Id{id}", async() =>
            {
                var @result = await _dataBaseOptionService.FindAsync(id);
                return(@result.Result);
            });

            return(new ResponseResult <XXXAo>
            {
                Result = result,
            });
        }
Example #3
0
            /// <summary>
            /// 模型验证
            /// </summary>
            public XXXAoValidator(IDataBaseOptionService dataBaseOptionService)
            {
                //Id必须
                RuleFor(x => x.Id).GreaterThan((uint)1).WithMessage("Id不能小于1")
                .MustAsync(async(s, a, x) =>
                {
                    bool IssuerValidate = false;
                    if ((await dataBaseOptionService.FindAsync(s.Id)).Result != null)
                    {
                        IssuerValidate = true;
                    }
                    return(IssuerValidate);
                }).WithMessage("数据库未找到对应数据数据不存在");

                RuleFor(t => t.UserName).NotEmpty().WithMessage("名称不能为空")
                .Length(1, 20).WithMessage("名称长度在1-20个字符之间");
            }