예제 #1
0
        //need BankAccount(IBAN), username, amount
        public async Task <ActionResult <MessageModel> > AddMoneyInBankAccount(ChargeAccountRequestModel requestModel)
        {
            var currentUser = HttpContext.User;

            return(await _chargeAccountService.AddMoney(requestModel, currentUser, requestModel.Username));
        }
예제 #2
0
        public async Task <ActionResult <MessageModel> > AddMoney(string cardNumber, string CVV, DateTime expireDate, ClaimsPrincipal currentUser, string username, decimal amount, IChargeAccountsService _chargeAccService)
        {
            var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username);

            ChargeAccount bankAccountsExists = null;
            Card          cardsExists        = null;

            if (currentUser.HasClaim(c => c.Type == "Roles"))
            {
                if (userAuthenticate != null)
                {
                    try
                    {
                        cardsExists = await dbContext.Cards.FirstOrDefaultAsync(x => x.CardNumber == cardNumber);

                        if (_BCrypt.AuthenticateDebitCardCVV(CVV, cardsExists))
                        {
                            if (cardsExists == null)
                            {
                                responseMessage.Message = "Debit Card not found";
                                return(StatusCode(404, responseMessage));
                            }
                            bankAccountsExists = await dbContext.ChargeAccounts.FirstOrDefaultAsync(x => x.Card == cardsExists);
                        }
                        else
                        {
                            responseMessage.Message = "Invalid Credentials";
                            return(StatusCode(400, responseMessage));
                        }
                    }
                    catch (NullReferenceException)
                    {
                        responseMessage.Message = "Debit Card not found";
                        return(StatusCode(404, responseMessage));
                    }
                }
                else
                {
                    responseMessage.Message = "User not found!";
                    return(StatusCode(404, responseMessage));
                }

                if (bankAccountsExists != null)
                {
                    try
                    {
                        if (cardsExists.CardExpirationDate < DateTime.Now)
                        {
                            responseMessage.Message = "Debit Card is expired";
                            return(StatusCode(406, responseMessage));
                        }

                        ChargeAccountRequestModel requestModel = new ChargeAccountRequestModel();
                        requestModel.ChargeAccount = bankAccountsExists;
                        requestModel.Amount        = amount;
                        await _chargeAccService.AddMoney(requestModel, currentUser, username);

                        responseMessage.Message = "Money deposited successfully";
                        return(StatusCode(200, responseMessage));
                    }
                    catch (NullReferenceException)
                    {
                        responseMessage.Message = "Bank Account not found";
                        return(StatusCode(404, responseMessage));
                    }
                }
                else if (bankAccountsExists == null)
                {
                    responseMessage.Message = "Bank Account not found";
                    return(StatusCode(404, responseMessage));
                }
            }
            responseMessage.Message = "You are not autorized to do such actions!";
            return(StatusCode(403, responseMessage));
        }