Пример #1
0
        /// <summary>
        /// 新增修改客户端
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <NarutoResult> AddUpdClient(ClientModel model)
        {
            #region 参数校检

            if (model == null)
            {
                return(new NarutoFailResult($"{nameof(model)}参数不能为空"));
            }
            if (model.ClientId.IsNullOfEmpty())
            {
                return(new NarutoFailResult($"{nameof(model.ClientId)}参数不能为空"));
            }
            if (model.ClientName.IsNullOfEmpty())
            {
                return(new NarutoFailResult($"{nameof(model.ClientName)}参数不能为空"));
            }
            if (model.AccessTokenLifetime <= 0)
            {
                return(new NarutoFailResult($"{nameof(model.AccessTokenLifetime)}访问周期不能小于0"));
            }
            if (model.IdentityTokenLifetime <= 0)
            {
                return(new NarutoFailResult($"{nameof(model.IdentityTokenLifetime)}身份周期不能小于0"));
            }
            #endregion
            //验证是否存在
            if ((await clientStorage.ExistsClientId(model.Id, model.ClientId)))
            {
                return(new NarutoFailResult("当前客户端id已经存在!"));
            }
            //访问存储接口
            var res = await clientStorage.AddUpdClient(model);

            if (res)
            {
                return(new NarutoSuccessResult("操作成功"));
            }
            return(new NarutoFailResult("操作失败"));
        }