Ejemplo n.º 1
0
        public async Task <ActionResult <MessageModel> > Withdraw(DebitCardRequestModel requestModel)
        {
            var    currentUser = HttpContext.User;
            string username    = currentUser.Claims.FirstOrDefault(currentUser => currentUser.Type == "Username").Value;

            return(await _debitCardService.Withdraw(requestModel.Card.CardNumber, requestModel.Card.Cvv, requestModel.Card.CardExpirationDate, currentUser, username, requestModel.Amount, requestModel.Reciever, _chargeAccountService));
        }
Ejemplo n.º 2
0
        //need username
        public async Task <ActionResult <MessageModel> > DeleteDebitCard(DebitCardRequestModel requestModel)
        {
            var currentUser = HttpContext.User;

            return(await _debitCardService.DeleteDebitCard(currentUser, requestModel, requestModel.Username));
        }
Ejemplo n.º 3
0
        //need bankaccount(IBAN), username, card()
        public async Task <ActionResult <MessageModel> > CreateDebitcard(DebitCardRequestModel requestModel)
        {
            var currentUser = HttpContext.User;

            return(await _debitCardService.CreateDebitCard(currentUser, requestModel.Username, requestModel.ChargeAccount, requestModel.Card));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <MessageModel> > DeleteDebitCard(ClaimsPrincipal currentUser, DebitCardRequestModel requestModel, string username)
        {
            string role = "";

            if (currentUser.HasClaim(c => c.Type == "Roles"))
            {
                string userRole = currentUser.Claims.FirstOrDefault(currentUser => currentUser.Type == "Roles").Value;
                role = userRole;
            }

            if (role == "Admin")
            {
                var user = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username);

                Card cardExists = null;


                if (user != null)
                {
                    try
                    {
                        cardExists = await dbContext.Cards.FirstOrDefaultAsync(x => x.CardNumber == requestModel.Card.CardNumber);
                    }
                    catch (NullReferenceException)
                    {
                        responseMessage.Message = "User doesn't have a Debit Card!";
                        return(StatusCode(400, responseMessage));
                    }
                }

                if (user == null)
                {
                    responseMessage.Message = "User not found!";
                    return(StatusCode(404, responseMessage));
                }
                else if (cardExists == null)
                {
                    responseMessage.Message = "User doesn't have a Debit Card!";
                    return(StatusCode(400, responseMessage));
                }

                dbContext.Cards.Remove(cardExists);
                await dbContext.SaveChangesAsync();

                responseMessage.Message = $"Succsesfully deleted {user.Username} Debit Card!";
                return(StatusCode(200, responseMessage));
            }
            else
            {
                responseMessage.Message = "You are not autorized to do such actions!";
                return(StatusCode(403, responseMessage));
            }
        }