public ActionResult Buy(TicketWedstrijd ticketWedstrijd) { try { ticketService = new TicketService(); bezoekerService = new BezoekerService(); bestellingService = new BestellingService(); shoppingCartDataService = new ShoppingCartDataService(); string user = User.Identity.GetUserId(); // Bestelling toevoegen indien nodig Bestelling bestelling = bestellingService.FindOpenstaandeBestellingDoorUser(user); int bestellingId; if (bestelling != null) { // toevoegen aan bestaande bestelling bestellingId = bestelling.id; } else { // nieuwe bestelling aanmaken bestellingId = bestellingService.CreateNieuweBestelling(0, user); } // Bezoeker toevoegen indien nodig if (bezoekerService.FindBezoeker(ticketWedstrijd.Bezoeker.rijksregisternummer) == null) { bezoekerService.AddBezoeker(ticketWedstrijd.Bezoeker); } try { // Ticket toevoegen Ticket ticket = ticketService.BuyTicket(bestellingId, ticketWedstrijd.SelectedVak, ticketWedstrijd.Stadion.id, ticketWedstrijd.Wedstrijd.id, user, ticketWedstrijd.Bezoeker.rijksregisternummer); // nieuwe ShoppingCartData toevoegen indien mogelijk shoppingCartDataService.AddShoppingCartData(user, ticket, bestellingId, ticketWedstrijd.Wedstrijd.id); } catch (TeveelTicketsException ex) { return(View("TeveelTickets")); } return(RedirectToAction("Success")); } catch { return(View("Fail")); } }
// GET: ShoppingCart public ActionResult Index() { shoppingCartDataService = new ShoppingCartDataService(); bestellingService = new BestellingService(); Bestelling bestelling = bestellingService.GetBestellingMetTicketsByUser(User.Identity.GetUserId()); // ViewModel opvullen ShoppingCart shoppingCart = new ShoppingCart(); shoppingCart.Bestelling = bestelling; shoppingCart.ShoppingCartItems = bestelling.ShoppingCartDatas; shoppingCart.Tickets = bestelling.Tickets; shoppingCart.TotaalPrijs = shoppingCartDataService.berekenTotaalPrijs(bestelling); return(View(shoppingCart)); }