public DatabaseContext()
 {
     Concerts = new ConcertContext();
     Tickets = new ConcertTicketContext();
     Customers = new CustomerContext();
     Purchase = new PurchaseTicketsModel();
     Venues = new VenueContext();
 }
 public List<ConcertTicket> WriteNewTicketToDb(PurchaseTicketsModel model)
 {
     return Context.Tickets.WriteNewTicketToDb(model);
 }
            public List<ConcertTicket> WriteNewTicketToDb(PurchaseTicketsModel model)
            {
                using (var insertConnection = WingtipTicketApp.CreateTenantSqlConnection())
                {
                    insertConnection.Open();

                    for (var i = 0; i < model.Quantity; i++)
                    {
                        var ticketName = String.Format("Ticket ({0} of {1}) for user {2} to concert-{3}", (i + 1), model.Quantity, model.CustomerName, model.ConcertId);
                        var insertQuery = String.Format(@"INSERT INTO Tickets (CustomerId, Name, TicketLevelId, ConcertId, PurchaseDate, SeatNumber) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')", model.CustomerId, ticketName, model.SeatSectionId, model.ConcertId, DateTime.Now, model.Seats[i]);

                        using (var insertCommand = new SqlCommand(insertQuery, insertConnection))
                        {
                            insertCommand.ExecuteNonQuery();
                        }
                    }

                    insertConnection.Close();
                    insertConnection.Dispose();
                }

                return ReturnPurchasedTicketsByConcertId(model.CustomerId, model.ConcertId);
            }
        public ActionResult PurchaseTicketsWithCreditCard(FindSeatsViewModel viewModel)
        {
            // Check Information
            if (!ModelState.IsValid)
            {
                return RedirectToAction("Index", "Home");
            }
            
            // Map to Domain Model
            var domainModel = new PurchaseTicketsModel()
            {
                ConcertId = viewModel.Purchase.ConcertId,
                SeatSectionId = viewModel.Purchase.SeatSectionId,
                Quantity = viewModel.Purchase.Quantity,
                Seats = viewModel.Purchase.Seats.Replace(" ", "").Split(',').ToList(),

                CustomerId = ((CustomerModel)Session["SessionUser"]).CustomerId,
                CustomerName = ((CustomerModel)Session["SessionUser"]).FirstName
            };

            // Purchase Tickets and Display Result
            var ticketsPurchased = _ticketRepository.WriteNewTicketToDb(domainModel);

            DisplayMessage(ticketsPurchased != null 
                ? string.Format("Successfully purchased tickets. You now have {0} tickets for this concert. Confirmation # {1}", ticketsPurchased.Count, ticketsPurchased[0].TicketId) 
                : "Failed to purchase tickets.");

            return RedirectToAction("Index", "Home");
        }