Example #1
0
        public async Task <IResultModel> BindRole(AccountRoleBindModel model)
        {
            var account = await Get(model.AccountId);

            if (account == null || account.Deleted)
            {
                return(ResultModel.Failed("账户不存在"));
            }

            var exists = await _roleRepository.ExistsAsync(model.RoleId);

            if (!exists)
            {
                return(ResultModel.Failed("角色不存在"));
            }

            //添加
            if (model.Checked)
            {
                exists = await _accountRoleRepository.Exists(model.AccountId, model.RoleId);

                if (!exists)
                {
                    var result = await _accountRoleRepository.AddAsync(new AccountRoleEntity { AccountId = model.AccountId, RoleId = model.RoleId });
                    await ClearCache(result, account.Id);

                    return(ResultModel.Result(result));
                }
                await ClearCache(true, account.Id);

                return(ResultModel.Success());
            }
            {
                //删除
                var result = await _accountRoleRepository.Delete(model.AccountId, model.RoleId);
                await ClearCache(result, account.Id);

                return(ResultModel.Result(result));
            }
        }
Example #2
0
        public async Task <IResultModel> BindRole(AccountRoleBindModel model)
        {
            var exists = await _accountRepository.ExistsAsync(model.AccountId);

            if (!exists)
            {
                return(ResultModel.Failed("账户不存在"));
            }

            exists = await _roleRepository.ExistsAsync(model.RoleId);

            if (!exists)
            {
                return(ResultModel.Failed("角色不存在"));
            }

            //添加
            if (model.Checked)
            {
                exists = await _accountRoleRepository.Exists(model.AccountId, model.RoleId);

                if (!exists)
                {
                    var result = await _accountRoleRepository.AddAsync(new AccountRole { AccountId = model.AccountId, RoleId = model.RoleId });

                    return(ResultModel.Result(result));
                }

                return(ResultModel.Success());
            }
            {
                //删除
                var result = await _accountRoleRepository.Delete(model.AccountId, model.RoleId);

                return(ResultModel.Result(result));
            }
        }