public GetBalancesResponse GetBalances(GetBalancesRequest request, IAuthContext authContext) { var balanceRepo = _unitOfWork.GetRepository <Balance>(); var balances = balanceRepo.GetList(x => x.AccountId.ToString() == request.AccountId); GetBalancesResponse response = new GetBalancesResponse(); response.Items = new List <GetBalancesResponseItem>(); foreach (Balance blc in balances) { response.Items.Add(new GetBalancesResponseItem() { Amount = blc.Amount, BalanceType = BalanceType.GetInstance(blc.BalanceType).Text, Currency = CurrencyType.GetInstance(blc.CurrencyType).Text }); } 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); }