public async Task <ActionResult <UserAccResponseModel> > GetAllUserBankAccounts(ClaimsPrincipal currentUser, string username, IChargeAccountsService chargeAccount, IDepositsService depositService, ICreditsService creditsService, IWalletsService walletsService) { var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username); if (currentUser.HasClaim(c => c.Type == "Roles")) { if (userAuthenticate != null) { var charges = await chargeAccount.GetBankAccountInfo(currentUser, username); var deposits = await depositService.GetDepositsInfo(currentUser, username); var wallets = await walletsService.GetWalletsInfo(currentUser, username); var credits = await creditsService.GetCreditInfo(currentUser, username); UserAccResponseModel userAcc = new UserAccResponseModel(); userAcc.UserChargeAcc = charges.Value; userAcc.UserCredits = credits.Value; userAcc.UserDeposits = deposits.Value; userAcc.UserWallets = wallets.Value; return(StatusCode(200, userAcc)); } responseMessage.Message = "User not found"; return(StatusCode(404, responseMessage)); } responseMessage.Message = "You are not logged in"; return(StatusCode(403, responseMessage)); }
public async Task <ActionResult <MessageModel> > GetPayOffInfo(ClaimsPrincipal currentUser, string username) { if (currentUser.HasClaim(c => c.Type == "Roles")) { var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username); CreditResponseModel creditResponseModel = new CreditResponseModel(); UserAccResponseModel userCredits = new UserAccResponseModel(); if (userAuthenticate == null) { responseMessage.Message = "User not found!"; return(StatusCode(404, responseMessage)); } else { ChargeAccount chargeAcc = await dbContext.ChargeAccounts.FirstOrDefaultAsync(x => x.UserId == userAuthenticate.Id); bool hasDeleted = false; foreach (var creditRef in dbContext.Credits.Where(x => x.UserId == userAuthenticate.Id)) { var credit = creditRef; if (credit == null) { responseMessage.Message = "You don't have a Credit"; return(StatusCode(400, responseMessage)); } await GetCreditPayOff(credit, username); if (credit.CreditAmountLeft == 0 && credit.CreditAmount > 0) { CreditRequestModel requestModel = new CreditRequestModel(); requestModel.Credit = credit; requestModel.Username = username; responseMessage.Message = "You have payed your Credit!"; await DeleteCreditFromPayOff(credit, chargeAcc); hasDeleted = true; } } await dbContext.SaveChangesAsync(); if (hasDeleted) { responseMessage.Message = ($"Successfully payed montly pay off! Credit payed successfully! The left amount from the credit is transfered to Bank Account with Iban: {chargeAcc.Iban}"); return(StatusCode(200, responseMessage)); } responseMessage.Message = "Successfully payed montly pay off!"; return(StatusCode(200, responseMessage)); } } responseMessage.Message = "You are not autorized to do such actions!"; return(StatusCode(403, responseMessage)); }
public async Task <ActionResult <ICollection <WalletResponseModel> > > GetWalletsInfo(ClaimsPrincipal currentUser, string username) { if (currentUser.HasClaim(c => c.Type == "Roles")) { var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username); UserAccResponseModel userWallets = new UserAccResponseModel(); if (userAuthenticate == null) { responseMessage.Message = "User not found!"; return(StatusCode(404, responseMessage)); } else { foreach (var walletRef in dbContext.Wallets.Where(x => x.UserId == userAuthenticate.Id)) { WalletResponseModel walletResponseModel = new WalletResponseModel(); var wallet = walletRef; walletResponseModel.IBAN = wallet.Iban; walletResponseModel.Amount = Math.Round(wallet.Amount, 2); walletResponseModel.CardNumber = wallet.CardNumber; if (walletResponseModel.CardNumber.StartsWith('5')) { walletResponseModel.CardBrand = "Master Card"; } else { walletResponseModel.CardBrand = "Visa"; } userWallets.UserWallets.Add(walletResponseModel); } if (userWallets.UserWallets.Count > 0) { return(StatusCode(200, userWallets.UserWallets.OrderBy(x => x.IBAN))); } responseMessage.Message = "You don't have a Wallet!"; return(StatusCode(400, responseMessage)); } } else { responseMessage.Message = "You are not authorized to do such actions"; return(StatusCode(403, responseMessage)); } }
public async Task <ActionResult <DepositResponseModel> > GetDividentsInfo(ClaimsPrincipal currentUser, string username) { if (currentUser.HasClaim(c => c.Type == "Roles")) { var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username); DepositResponseModel depositResponseModel = new DepositResponseModel(); UserAccResponseModel userDeposits = new UserAccResponseModel(); DividentValidation dividentService = new DividentValidation(); if (userAuthenticate == null) { responseMessage.Message = "User not found"; return(StatusCode(404, responseMessage)); } else { bool isChecked = false; foreach (var depositRef in dbContext.Deposits.Where(x => x.UserId == userAuthenticate.Id)) { await dividentService.GetDividentPayment(depositRef); isChecked = true; } if (isChecked) { responseMessage.Message = "Check susscessfull"; return(StatusCode(200, depositResponseModel)); } else { responseMessage.Message = "You don't have a Deposit!"; return(StatusCode(400, responseMessage)); } } } else { responseMessage.Message = "You are not authorized to do such actions"; return(StatusCode(403, responseMessage)); } }
public async Task <ActionResult <ICollection <ChargeAccountResponseModel> > > GetBankAccountInfo(ClaimsPrincipal currentUser, string username) { if (currentUser.HasClaim(c => c.Type == "Roles")) { var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username); UserAccResponseModel userChargeAccounts = new UserAccResponseModel(); if (userAuthenticate == null) { responseModel.Message = "User not found"; return(StatusCode(404, responseModel)); } else { List <ChargeAccountResponseModel> charges = new List <ChargeAccountResponseModel>(); foreach (var chargeAccRef in dbContext.ChargeAccounts.Where(x => x.UserId == userAuthenticate.Id)) { ChargeAccountResponseModel chargeAccResponseModel = new ChargeAccountResponseModel(); var chargeAcc = chargeAccRef; chargeAccResponseModel.IBAN = chargeAcc.Iban; chargeAccResponseModel.Amount = Math.Round(chargeAcc.Amount, 2); charges.Add(chargeAccResponseModel); } if (charges.Count > 0) { return(StatusCode(200, charges.OrderBy(x => x.IBAN))); } responseModel.Message = "You don't have a Charge Account!"; return(StatusCode(400, responseModel)); } } else { responseModel.Message = "You are not authorized to do such actions"; return(StatusCode(403, responseModel)); } }