コード例 #1
0
        public ActionResult Payment(Payment paymentModel)
        {
            if (ModelState.IsValid)
            {   // Check if client is older than 18:
                if (paymentModel.DateOfBirth.Year < DateTime.Now.Year - 18)
                {
                    List <Ticket> tickets = GetSessionTickets();
                    ticketRepository.AddTickets(tickets);

                    foreach (var ticket in tickets)
                    {
                        ticket.Event = ticketRepository.GetEvent(ticket.EventId);
                        ticket.Event.CurrentTickets = ticket.Event.CurrentTickets - ticket.Amount;
                    }

                    Order order = new Order();
                    order.Tickets       = tickets; // remove?
                    order.FirstName     = paymentModel.FirstName;
                    order.LastName      = paymentModel.LastName;
                    order.Email         = paymentModel.Email;
                    order.IsPaid        = true; // never false, because a real payment system lacks in this project
                    order.PaymentMethod = paymentModel.SelectedPaymentMethod;
                    order.OrderPlaced   = DateTime.Now;

                    ticketRepository.AddOrder(order);

                    return(RedirectToAction("PaymentResult", "Ticket", order));
                }
                else
                {
                    ModelState.AddModelError("", "You have to be older than 18 to order a ticket for Haarlem Festival. Sorry!");
                }
            }

            // Lists are not passed with model, fill again:
            paymentModel.PaymentMethods = new List <string>(new string[] { "Cash at the ticket counter", "iDeal", "Visa", "PayPal" });
            return(View(paymentModel));
        }