Example #1
0
        public static TicketPurchase CreateTicket(Event Event, int tktQty)
        {
            TicketPurchase ticket = new TicketPurchase();

            ticket.Id             = Guid.NewGuid();
            ticket.Event          = Event;
            ticket.TicketQuantity = tktQty;

            return(ticket);
        }
        public static TicketPurchase CreateTicket(Event Event, int tktQty)
        {
            TicketPurchase ticket = new TicketPurchase();

            ticket.Id = Guid.NewGuid();
            ticket.Event = Event;
            ticket.TicketQuantity = tktQty;

            return ticket;
        }
Example #3
0
        public TicketPurchase PurchaseTicketWith(Guid reservationId)
        {
            if (!CanPurchaseTicketWith(reservationId))
            {
                throw new ApplicationException(DetermineWhyATicketCannotbePurchasedWith(reservationId));
            }

            TicketReservation reservation = GetReservationWith(reservationId);

            TicketPurchase ticket = TicketPurchaseFactory.CreateTicket(this, reservation.TicketQuantity);

            reservation.HasBeenRedeemed = true;

            PurchasedTickets.Add(ticket);

            return(ticket);
        }
        public Event FindBy(Guid id)
        {
            Event Event = default(Event);

            string queryString = "SELECT * FROM dbo.Events WHERE Id = @EventId " +
                                 "SELECT * FROM dbo.PurchasedTickets WHERE EventId = @EventId " +
                                 "SELECT * FROM dbo.ReservedTickets WHERE EventId = @EventId;";

            using (SqlConnection connection =
                   new SqlConnection(connectionString))
            {
                SqlCommand command = connection.CreateCommand();
                command.CommandText = queryString;

                SqlParameter Idparam = new SqlParameter("@EventId", id.ToString());
                command.Parameters.Add(Idparam);

                connection.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        reader.Read();
                        Event = new Event();
                        Event.PurchasedTickets = new List<TicketPurchase>();
                        Event.ReservedTickets = new List<TicketReservation>();
                        Event.Allocation = int.Parse(reader["Allocation"].ToString());
                        Event.Id = new Guid(reader["Id"].ToString());
                        Event.Name = reader["Name"].ToString();

                        if (reader.NextResult())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    TicketPurchase ticketPurchase = new TicketPurchase();
                                    ticketPurchase.Id = new Guid(reader["Id"].ToString());
                                    ticketPurchase.Event = Event;
                                    ticketPurchase.TicketQuantity = int.Parse(reader["TicketQuantity"].ToString());
                                    Event.PurchasedTickets.Add(ticketPurchase);
                                }
                            }
                        }

                        if (reader.NextResult())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    TicketReservation ticketReservation = new TicketReservation();
                                    ticketReservation.Id = new Guid(reader["Id"].ToString());
                                    ticketReservation.Event = Event;
                                    ticketReservation.ExpiryTime = DateTime.Parse(reader["ExpiryTime"].ToString());
                                    ticketReservation.TicketQuantity = int.Parse(reader["TicketQuantity"].ToString());
                                    ticketReservation.HasBeenRedeemed = bool.Parse(reader["HasBeenRedeemed"].ToString());
                                    Event.ReservedTickets.Add(ticketReservation);
                                }
                            }
                        }
                    }
                }
            }

            return Event;
        }