示例#1
0
 public IActionResult WithdrawFunds()
 {
     if (HttpContext.User.Identity.IsAuthenticated)
     {
         ViewBag.IsDeposit = false;
         TransactionFormModel transactionFormModel = new TransactionFormModel()
         {
             Messages = messages,
         };
         return(View("Transaction", transactionFormModel));
     }
     else
     {
         return(RedirectToAction("Index"));
     }
 }
示例#2
0
        public IActionResult WithdrawFunds(TransactionFormModel transactionFormModel)
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                if (transactionFormModel.Amount <= 0)
                {
                    Message errorMessage = new Message()
                    {
                        Text = "You cannot withdraw zero or a negative amount. Please try again.",
                        Type = MessageType.ERROR,
                    };
                    transactionFormModel.Messages = new List <Message> {
                        errorMessage
                    };
                    ViewBag.IsDeposit = false;
                    return(View("Transaction", transactionFormModel));
                }

                User            user     = securityHelper.GetUserFromIdentity(HttpContext.User.Identity as ClaimsIdentity);
                ServiceResponse response = transactionService.CreateTransaction(user.Id, transactionFormModel.Amount * -1);
                messageHelper.AppendResponseMessages(messages, response);
                Transaction transaction = response.ResponseObject as Transaction;
                if (transaction != null)
                {
                    messageHelper.AddMessagesToSession(messages, HttpContext);
                    return(RedirectToAction("Dashboard"));
                }
                else
                {
                    ViewBag.IsDeposit             = false;
                    transactionFormModel.Messages = messages;
                    return(View("Transaction", transactionFormModel));
                }
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }