public IActionResult GetWallet(int userId) { UserWalletInfo uwi = _walletService.GetWallet(userId); if (uwi != null) { return(new JsonResult(uwi) { StatusCode = StatusCodes.Status200OK }); } return(new JsonResult(PaymentConstants.NOT_FOUND_WALLET) { StatusCode = StatusCodes.Status404NotFound }); }
public UserWalletInfo GetWallet(int userId) { UserWalletInfo userWalletInfo = null; Wallet wallet = _walletRepository .GetAll() .Where(w => w.UserId == userId) .FirstOrDefault(); if (wallet != null) { userWalletInfo = new UserWalletInfo() { Id = wallet.Id, Balance = wallet.Balance, UserId = wallet.UserId }; List <Transaction> transactions = _transactionRepository.GetAll().Where(t => t.SenderId == userId || t.ReceiverId == userId).ToList(); UserTranscationInfo uti = null; foreach (var transaction in transactions) { uti = new UserTranscationInfo() { Amount = transaction.Amount, Detail = transaction.Detail, State = transaction.State, Time = transaction.Time, Type = transaction.Type }; userWalletInfo.Transactions.Add(uti); } userWalletInfo.Transactions.OrderBy(t => t.Time); } return(userWalletInfo); }