public GetAccountsResponse GetAccounts(GetAccountsRequest request, IAuthContext authContext)
        {
            var accountRepo = _unitOfWork.GetRepository <Account>();
            var accounts    = accountRepo.GetAsyncQueryable(x => x.UserId.ToString() == authContext.UserId, w => w.AccountIdentifications).Result.ToList();

            GetAccountsResponse response = new GetAccountsResponse();

            response.Items = new List <GetAccountsResponseItem>();

            foreach (Account acc in accounts)
            {
                var account = new GetAccountsResponseItem()
                {
                    AccountId         = acc.Id.ToString(),
                    AccountType       = AccountType.GetInstance(acc.AccountType).Text,
                    CurrencyType      = CurrencyType.GetInstance(acc.CurrencyType).Text,
                    Name              = acc.Name,
                    ProviderAccountId = acc.ProviderAccountId,
                    ProviderName      = Provider.GetInstance(acc.ProviderId).Text
                };

                foreach (AccountIdentification ai in acc.AccountIdentifications)
                {
                    account.AccountIdentification.Add(AccountIdentificationType.GetInstance(ai.AccountIdentificationTypeId).Text + ": " + ai.Identification);
                }

                response.Items.Add(account);
            }

            return(response);
        }
        public GetUserInfoResponse GetUserInfo(GetUserInfoRequest request, IAuthContext authContext)
        {
            GetUserInfoResponse response = new GetUserInfoResponse();

            response.UserProviders = new List <UserProviderInfo>();

            var userProviderRepo = _unitOfWork.GetRepository <UserProvider>();
            var userAccountRepo  = _unitOfWork.GetRepository <Account>();
            var userAccountIdentificaitonRepo = _unitOfWork.GetRepository <AccountIdentification>();
            var userBalanceRepo     = _unitOfWork.GetRepository <Balance>();
            var userTransactionRepo = _unitOfWork.GetRepository <Transaction>();

            var userProviders = userProviderRepo.GetList(x => x.UserId.ToString() == authContext.UserId);

            foreach (var up in userProviders)
            {
                UserProviderInfo info = new UserProviderInfo();
                info.ProviderId      = up.Provider.ToString();
                info.ProviderName    = Provider.GetInstance(up.Provider).Text;
                info.ProviderLogoUrl = Provider.GetInstance(up.Provider).FlagUrl;
                info.Accounts        = new List <UserAccount>();

                var userAccounts = userAccountRepo.GetList(x => x.UserId.ToString() == authContext.UserId && x.ProviderId == up.Provider);

                foreach (var a in userAccounts)
                {
                    UserAccount account = new UserAccount();
                    account.AccountId             = a.Id.ToString();
                    account.AccountType           = AccountType.GetInstance(a.AccountType).Text;
                    account.CurrencyType          = CurrencyType.GetInstance(a.CurrencyType).Text;
                    account.Name                  = a.Name;
                    account.ProviderAccountId     = a.ProviderAccountId;
                    account.AccountIdentification = new List <string>();
                    account.Balances              = new List <UserBalance>();
                    account.Transactions          = new List <UserTransaction>();

                    var userAccountIdentifications = userAccountIdentificaitonRepo.GetList(x => x.AccountId == a.Id);

                    foreach (var ai in userAccountIdentifications)
                    {
                        account.AccountIdentification.Add(AccountIdentificationType.GetInstance(ai.AccountIdentificationTypeId).Text + ": " + ai.Identification);
                    }

                    var userBalances = userBalanceRepo.GetList(x => x.AccountId == a.Id);

                    foreach (var b in userBalances)
                    {
                        account.Balances.Add(new UserBalance()
                        {
                            Amount      = b.Amount,
                            BalanceType = BalanceType.GetInstance(b.BalanceType).Text,
                            Currency    = CurrencyType.GetInstance(b.CurrencyType).Text
                        });
                    }

                    var userTransactions = userTransactionRepo.GetList(x => x.AccountId == a.Id);

                    foreach (var t in userTransactions)
                    {
                        account.Transactions.Add(new UserTransaction()
                        {
                            Amount                = t.Amount,
                            Date                  = t.Date.ToString(),
                            Description           = t.Description,
                            MerchantCategory      = MerchantCategory.GetInstance(t.MerchantCategory).Text,
                            ProviderTransactionId = t.ProviderTransactionId,
                            TransactionCategory   = TransactionCategory.GetInstance(t.TransactionCategory).Text,
                            TransactionStatus     = TransactionStatus.GetInstance(t.TransactionStatus).Text,
                            TransactionType       = TransactionType.GetInstance(t.TransactionType).Text
                        });
                    }

                    info.Accounts.Add(account);
                }

                response.UserProviders.Add(info);
            }

            return(response);
        }