示例#1
0
        public ActionResult ConfirmPayment(ConfirmPaymentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Confirmation", model));
            }

            var             data            = TempData[VisaPaymentViewModelKey] as VisaPaymentViewModel;
            List <Purchase> basket          = GetBasket();
            decimal         amountOfPayment = basket.Sum(b => b.Price * b.Quantity);

            PaymentStatus result = PayOrderUsingPaymentService(data, basket, amountOfPayment);

            if (result != PaymentStatus.SuccessfulPayment)
            {
                var message = string.Empty;

                if (result == PaymentStatus.CardDoesNotExist)
                {
                    message = Resource.CardNotFound;
                }

                if (result == PaymentStatus.NotEnoughMoney)
                {
                    message = Resource.NotEnoughMoney;
                }

                if (result == PaymentStatus.PaymentFailed)
                {
                    message = Resource.PaymentFailed;
                }

                return(RedirectToAction("ErrorMessage", "Error", new { message }));
            }

            const string recipientEmailAddress = "*****@*****.**";

            _emailService.Send(recipientEmailAddress, "new purchase", $"Amount of {amountOfPayment}");

            int orderId = CreateOrUpdateCurrentOrder(basket);

            _orderService.Pay(orderId);
            Session[Basket] = null;

            return(View("OrderPaid"));
        }
        public async Task <IActionResult> Index(ConfirmPaymentViewModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            var marker = await _context.Markers.FirstOrDefaultAsync(x => x.Id == model.MarkerId);

            var seedling = await _context.Seedlings.FirstOrDefaultAsync(x => x.Id == model.SeedlingId);

            var payment = new Payment
            {
                User            = user,
                Marker          = marker,
                Seedling        = seedling,
                PurchasedAmount = model.PurchasedAmount,
                Price           = model.Price
            };
            await _context.Payments.AddAsync(payment);

            await new EmailService().SendEmailAsync(user.Email, "Статус оплати",
                                                    $"Дорога(-ий) {user.Name} {user.UserSurname}," +
                                                    $" дякуємо вам за оплату! Зовсім скоро ви отримаєте електронне повідомлення про статус оплати!");
            if (seedling.Amount > 0)
            {
                seedling.Amount -= model.PurchasedAmount;
                _context.Update(seedling);
            }
            if (marker.PlantCount > 0)
            {
                marker.PlantCount -= model.PurchasedAmount;
                _context.Update(marker);
            }
            if (marker.PlantCount == 0)
            {
                marker.isPlantingFinished = true;
                _context.Update(marker);
            }

            await _context.SaveChangesAsync();


            return(RedirectToAction("Index", "Map"));
        }
        public async Task <IActionResult> Index(PaymentViewModel m)
        {
            var user = await _userManager.GetUserAsync(User);

            var marker = await _context.Markers.FirstOrDefaultAsync(x => x.Id == m.MarkerId);

            var seedling = await _context.Seedlings.FirstOrDefaultAsync(x => x.Id == m.SeedlingId);

            var model = new ConfirmPaymentViewModel()
            {
                MarkerId        = m.MarkerId,
                SeedlingId      = m.SeedlingId,
                MarkerTitle     = marker.Title,
                PurchasedAmount = m.PlantCount,
                Price           = m.PlantCount * seedling.Price,
                Seedling        = seedling.Name,
                Name            = user.Name,
                Surname         = user.UserSurname,
                Email           = user.Email
            };

            return(View(model));
        }
 /// <summary>
 /// 确认支付页面
 /// </summary>
 public ConfirmPaymentView()
 {
     this.InitializeComponent();
     ViewModel   = new ConfirmPaymentViewModel();
     DataContext = ViewModel;
 }