public async Task UpdateWallet(UpdateWalletDto model, long idUser) { try { var user = await _weGOPAYDbContext.User.Where(s => s.Id == idUser).FirstOrDefaultAsync(); var userId = user.UserId; var nUpdate = await _weGOPAYDbContext.Wallet.FindAsync(model.Id); if (nUpdate != null) { nUpdate.Id = model.Id; nUpdate.WalletCreationDate = DateTime.UtcNow; nUpdate.NairaBalance = GetNairaBalance(model.Currency, model.Amount, userId); nUpdate.EuroBalance = GetEuroBalance(model.Currency, model.Amount, userId); nUpdate.PoundBalance = GetPoundBalance(model.Currency, model.Amount, userId); nUpdate.USDBalance = GetDollarBalance(model.Currency, model.Amount, userId); nUpdate.YenBalance = GetYenBalance(model.Currency, model.Amount, userId); } ; _weGOPAYDbContext.Entry(nUpdate).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } catch (Exception ex) { throw ex; } }
public async Task UpdateUser(UpdateUserDto model, long id) { try { var uUser = await _weGOPAYDbContext.User.FindAsync(id); if (uUser == null) { return; } uUser.Id = model.Id; uUser.Fullname = model.Fullname; uUser.CountryOfResidence = model.CountryOfResidence; uUser.DateUpdated = DateTime.UtcNow; uUser.IsUpdated = true; _weGOPAYDbContext.Entry(uUser).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } catch (Exception ex) { throw ex; } }
public async Task MakeTransactionResponse(ResponseWalletTransactionDto model, long requestId) { #region Transaction Response Completion try { #region Wallets/WalletTransaction Queries //Checks the Response Client wallet var getResponseWallet = await _weGOPAYDbContext.Wallet.Where(s => s.UserId == model.UserId).FirstOrDefaultAsync(); //Checks the requested wallet transaction var nRequest = await _weGOPAYDbContext.WalletTransaction.Where(x => x.Id == requestId).FirstOrDefaultAsync(); //Checks the Request Client wallet var getRequestWallet = await _weGOPAYDbContext.Wallet.Where(s => s.UserId == nRequest.UserId).FirstOrDefaultAsync(); #endregion #region Naira to Dollar Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Naira && getRequestWallet.NairaBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.USDollar) { var currentNairaBalance = getRequestWallet.NairaBalance - nRequest.Amount; var currentDollarBalance = getRequestWallet.USDBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.NairaBalance = currentNairaBalance; getRequestWallet.USDBalance = currentDollarBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Naira) { var currentDollarBalance = getResponseWallet.USDBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentNairaBalance = getResponseWallet.NairaBalance + nRequest.Amount; //Updating the response Client getResponseWallet.USDBalance = currentDollarBalance; getResponseWallet.NairaBalance = currentNairaBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Dollar to Naira Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.USDollar && getRequestWallet.USDBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.Naira) { var currentDollarBalance = getRequestWallet.USDBalance - nRequest.Amount; var currentNairaBalance = getRequestWallet.NairaBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.NairaBalance = currentNairaBalance; getRequestWallet.USDBalance = currentDollarBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Naira) { var currentNairaBalance = getResponseWallet.NairaBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentDollarBalance = getResponseWallet.USDBalance + nRequest.Amount; //Updating the response Client getResponseWallet.USDBalance = currentDollarBalance; getResponseWallet.NairaBalance = currentNairaBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Dollar to Pounds Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.USDollar && getRequestWallet.USDBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.BritishPound) { var currentPoundBalance = getRequestWallet.PoundBalance - nRequest.Amount; var currentDollarBalance = getRequestWallet.USDBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.PoundBalance = currentPoundBalance; getRequestWallet.USDBalance = currentDollarBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.USDollar) { var currentPoundBalance = getResponseWallet.NairaBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentDollarBalance = getResponseWallet.USDBalance + nRequest.Amount; //Updating the response Client getResponseWallet.PoundBalance = currentPoundBalance; getResponseWallet.USDBalance = currentDollarBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Pounds to Dollar Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.BritishPound && getRequestWallet.USDBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.USDollar) { var currentPoundBalance = getRequestWallet.PoundBalance - nRequest.Amount; var currentDollarBalance = getRequestWallet.USDBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.PoundBalance = currentPoundBalance; getRequestWallet.USDBalance = currentDollarBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.BritishPound) { var currentDollarBalance = getResponseWallet.USDBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentPoundBalance = getResponseWallet.PoundBalance + nRequest.Amount; //Updating the response Client getResponseWallet.PoundBalance = currentPoundBalance; getResponseWallet.USDBalance = currentDollarBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Pounds to Euro Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.BritishPound && getRequestWallet.USDBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.Euro) { var currentPoundBalance = getRequestWallet.PoundBalance - nRequest.Amount; var currentEuroBalance = getRequestWallet.EuroBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.PoundBalance = currentPoundBalance; getRequestWallet.USDBalance = currentEuroBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.BritishPound) { var currentEuroBalance = getResponseWallet.EuroBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentPoundBalance = getResponseWallet.PoundBalance + nRequest.Amount; //Updating the response Client getResponseWallet.PoundBalance = currentPoundBalance; getResponseWallet.EuroBalance = currentEuroBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Euro to Pounds Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Euro && getRequestWallet.USDBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.BritishPound) { var currentEuroBalance = getRequestWallet.EuroBalance - nRequest.Amount; var currentPoundBalance = getRequestWallet.PoundBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.PoundBalance = currentPoundBalance; getRequestWallet.USDBalance = currentEuroBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.BritishPound) { var currentPoundBalance = getResponseWallet.PoundBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentEuroBalance = getResponseWallet.EuroBalance + nRequest.Amount; //Updating the response Client getResponseWallet.PoundBalance = currentPoundBalance; getResponseWallet.EuroBalance = currentEuroBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Naira to Pounds Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Naira && getRequestWallet.NairaBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.BritishPound) { var currentNairaBalance = getRequestWallet.NairaBalance - nRequest.Amount; var currentPoundBalance = getRequestWallet.PoundBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.NairaBalance = currentNairaBalance; getRequestWallet.PoundBalance = currentPoundBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Naira) { var currentPoundBalance = getResponseWallet.PoundBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentNairaBalance = getResponseWallet.NairaBalance + nRequest.Amount; //Updating the response Client getResponseWallet.PoundBalance = currentPoundBalance; getResponseWallet.NairaBalance = currentNairaBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion #region Pounds to Naira Transaction using (var transaction = _weGOPAYDbContext.Database.BeginTransaction()) { if (nRequest.RequestCurrency == (int)CurrencyEnum.BritishPound && getRequestWallet.NairaBalance >= nRequest.Amount) { if (getRequestWallet != null) { if (nRequest.ResponseCurrency == (int)CurrencyEnum.Naira) { var currentPoundBalance = getRequestWallet.PoundBalance - nRequest.Amount; var currentNairaBalance = getRequestWallet.NairaBalance + ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); //Updating the Request Client getRequestWallet.NairaBalance = currentNairaBalance; getRequestWallet.PoundBalance = currentPoundBalance; _weGOPAYDbContext.Entry(getRequestWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } if (getResponseWallet != null) { if (nRequest.RequestCurrency == (int)CurrencyEnum.Naira) { var currentNairaBalance = getResponseWallet.NairaBalance - ConvertedAmount(nRequest.RequestCurrency, nRequest.ResponseCurrency, nRequest.Amount); var currentPoundBalance = getResponseWallet.PoundBalance + nRequest.Amount; //Updating the response Client getResponseWallet.PoundBalance = currentPoundBalance; getResponseWallet.NairaBalance = currentNairaBalance; _weGOPAYDbContext.Entry(getResponseWallet).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); } } } transaction.Commit(); } #endregion //Update the wallet transactions #region Update transaction Status to Responded if (nRequest != null) { nRequest.TransactionStatus = (int)TransactionStatus.Responded; } _weGOPAYDbContext.Entry(nRequest).State = EntityState.Modified; await _weGOPAYDbContext.SaveChangesAsync(); #endregion } catch (Exception ex) { throw ex; } #endregion }