Exemplo n.º 1
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(ClientsDto input)
        {
            try
            {
                _dbContext.Ado.BeginTran();
                var model = _mapper.Map <ClientsDto, Clients>(input);
                if (model.Id > 0)
                {
                    await _dbContext.Updateable(model).ExecuteCommandAsync();
                    await SaveClientGrantTypes(input.AllowedGrantTypes, model.Id, true);
                    await SaveClientScope(input.AllowedScopes, model.Id, true);
                    await SaveClientSecret(input.ClientSecrets, model.Id, true);

                    _dbContext.Ado.CommitTran();
                    return;
                }
                var mid = await _dbContext.Insertable(model).ExecuteReturnIdentityAsync();
                await SaveClientGrantTypes(input.AllowedGrantTypes, mid);
                await SaveClientScope(input.AllowedScopes, mid);
                await SaveClientSecret(input.ClientSecrets, mid);

                _dbContext.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                _dbContext.Ado.RollbackTran();
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 用户授权角色
        /// </summary>
        public async Task <bool> ToRole(ToRoleInput input)
        {
            if (input.Status)
            {
                await _dbContext.Insertable(new Permissions
                {
                    RoleId     = input.RoleId,
                    UserId     = input.UserId,
                    MenuId     = input.MenuId,
                    BtnFunId   = input.BtnFunId,
                    Types      = input.Types,
                    CreateTime = DateTime.Now
                }).ExecuteCommandAsync();
            }
            else
            {
                switch (input.Types)
                {
                case 2:
                    await _dbContext.Deleteable <Permissions>()
                    .Where(m => m.UserId == input.UserId && m.RoleId == input.RoleId && m.Types == 2)
                    .ExecuteCommandAsync();

                    break;

                case 3:
                    await _dbContext.Deleteable <Permissions>()
                    .Where(m => m.BtnFunId == input.BtnFunId && m.RoleId == input.RoleId && m.MenuId == input.MenuId && m.Types == 3)
                    .ExecuteCommandAsync();

                    break;
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 分配路由
 /// </summary>
 public async Task <bool> ToAccReRouteAsync(ToAccReRouteInput input)
 {
     if (input.Type == 0)
     {
         await _dbContext.Deleteable <ConfigReRoutes>()
         .Where(f => f.KeyId == input.KeyId && f.ReRouteId == input.ReRouteId)
         .ExecuteCommandAsync();
     }
     else
     {
         await _dbContext.Insertable(new ConfigReRoutes { KeyId = input.KeyId, ReRouteId = input.ReRouteId })
         .ExecuteCommandAsync();
     }
     return(true);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 分配客户端
 /// </summary>
 public async Task <bool> ToAccReRouteAsync(ToAccGroupInput input)
 {
     if (input.Type == 0)
     {
         await _dbContext.Deleteable <ClientGroup>()
         .Where(f => f.GroupId == input.GroupId && f.Id == input.KeyId)
         .ExecuteCommandAsync();
     }
     else
     {
         await _dbContext.Insertable(new ClientGroup { GroupId = input.GroupId, Id = input.KeyId })
         .ExecuteCommandAsync();
     }
     return(true);
 }
Exemplo n.º 5
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(UserDto input)
        {
            input.KeyId = input.KeyId ?? Guid.Empty;
            var model = _mapper.Map <UserDto, User>(input);

            if (model.KeyId != Guid.Empty)
            {
                model.UpdateTime = DateTime.Now;
                if (model.Password.IsNotNullAndWhiteSpace())
                {
                    model.Salt     = Randoms.CreateRandomValue(8, false);
                    model.Password = $"{model.Password}+_(QVQ)_+{model.Salt}".ToMd5();
                    await _dbContext.Updateable(model)
                    .IgnoreColumns(it => new { it.Account, it.CreateTime })
                    .ExecuteCommandAsync();
                }
                else
                {
                    await _dbContext.Updateable(model)
                    .IgnoreColumns(it => new { it.Account, it.Password, it.Salt, it.CreateTime })
                    .ExecuteCommandAsync();
                }
            }
            else
            {
                model.CreateTime = DateTime.Now;
                model.UpdateTime = DateTime.Now;
                model.Salt       = Randoms.CreateRandomValue(8, false);
                model.Password   = $"{model.Password}+_(QVQ)_+{model.Salt}".ToMd5();
                await _dbContext.Insertable(model).ExecuteCommandAsync();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(ApiResource input)
        {
            try
            {
                _dbContext.Ado.BeginTran();
                if (input.Id > 0)
                {
                    var scope = await _dbContext.Queryable <ApiScope>().FirstAsync(o => o.ApiResourceId == input.Id);

                    input.Updated = DateTime.Now;
                    await _dbContext.Updateable(input).IgnoreColumns(it => new { it.Created })
                    .ExecuteCommandAsync();

                    if (scope != null)
                    {
                        scope.Name        = input.Name;
                        scope.DisplayName = input.DisplayName;
                        scope.Description = input.Description;
                        await _dbContext.Updateable(scope).IgnoreColumns(it => new { it.ApiResourceId })
                        .ExecuteCommandAsync();
                    }
                    _dbContext.Ado.CommitTran();
                    return;
                }
                input.Created     = DateTime.Now;
                input.NonEditable = 0;
                var rid = await _dbContext.Insertable(input).ExecuteReturnIdentityAsync();

                await _dbContext.Insertable(new ApiScope
                {
                    ApiResourceId           = rid,
                    Description             = input.Description,
                    DisplayName             = input.DisplayName,
                    Emphasize               = false,
                    Name                    = input.Name,
                    Required                = false,
                    ShowInDiscoveryDocument = true
                }).ExecuteCommandAsync();

                _dbContext.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                _dbContext.Ado.RollbackTran();
                throw ex;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(ReRoute input)
        {
            if (input.ReRouteId > 0)
            {
                await _dbContext.Updateable(input).ExecuteCommandAsync();

                return;
            }
            await _dbContext.Insertable(input).ExecuteCommandAsync();
        }
Exemplo n.º 8
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(AuthGroup input)
        {
            if (input.GroupId > 0)
            {
                await _dbContext.Updateable(input).ExecuteCommandAsync();

                return;
            }
            await _dbContext.Insertable(input).ExecuteCommandAsync();
        }
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(GlobalConfiguration input)
        {
            if (input.KeyId > 0)
            {
                await _dbContext.Updateable(input).ExecuteCommandAsync();

                return;
            }
            await _dbContext.Insertable(input).ExecuteCommandAsync();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(RoleDto input)
        {
            input.KeyId = input.KeyId ?? Guid.Empty;
            var model = _mapper.Map <RoleDto, Role>(input);

            if (model.KeyId != Guid.Empty)
            {
                await _dbContext.Updateable(model)
                .IgnoreColumns(it => new { it.CreateTime })
                .ExecuteCommandAsync();
            }
            else
            {
                model.CreateTime = DateTime.Now;
                await _dbContext.Insertable(model).ExecuteCommandAsync();
            }
        }