Beispiel #1
0
        private AccountRole ValidateField(Guid accountCode, Guid roleCode, bool isRKAdmin, Guid clientId)
        {
            try
            {
                ApplicationStore appStore;
                AccountRole      _accountRole;

                if (accountCode.IsNull())
                {
                    throw new ArgumentException("Código da conta não informado");
                }

                if (roleCode.IsNull())
                {
                    throw new ArgumentException("Código do grupo não informado");
                }

                var _role = roleRepository.Get(roleCode, null);

                if (_role.IsNull())
                {
                    throw new ArgumentException("Grupo não encontrado");
                }

                var _account = accountRepository.Get(accountCode);

                if (_account.IsNull())
                {
                    throw new ArgumentException("Usuário não encontrada");
                }

                _accountRole = accountRoleRepository.Get(accountCode, roleCode);

                if (!isRKAdmin)
                {
                    appStore = applicationStoreRepository.GetByClientId(clientId);

                    if (appStore.IsNull())
                    {
                        throw new ArgumentException("Credenciais inválidas");
                    }

                    var _permission = permissionRepository.GetPermission(_role.Code);

                    if (_permission.IsNull())
                    {
                        throw new ArgumentException("Permissão não encontrada");
                    }

                    if (appStore.ApplicationCode != _permission.Resource.ApplicationCode)
                    {
                        throw new ArgumentException("Não é possível realizar essa operação.");
                    }
                }

                return(_accountRole);
            }
            catch (Exception)
            {
                throw;
            }
        }