コード例 #1
0
        public static TicketReservation CreateReservation(Event Event, int tktQty)
        {
            TicketReservation reservation = new TicketReservation();
            reservation.Id = Guid.NewGuid();
            reservation.Event = Event;
            reservation.ExpiryTime = DateTime.Now.AddMinutes(1);
            reservation.TicketQuantity = tktQty;

            return reservation;
        }
コード例 #2
0
        public static TicketReservation CreateReservation(Event Event, int tktQty)
        {
            TicketReservation reservation = new TicketReservation();

            reservation.Id             = Guid.NewGuid();
            reservation.TicketQuantity = tktQty;
            reservation.Event          = Event;
            reservation.ExpiryTime     = DateTime.Now.AddMinutes(1D);

            return(reservation);
        }
コード例 #3
0
 public static TicketReservation CreateReservation(Event Event, int tktQty)
 {
     TicketReservation reservation = new TicketReservation()
                                         {
                                             Event = Event,
                                             ExpiryTime = DateTime.Now.AddMinutes(1),
                                             HasBeenRedeemed = false,
                                             Id = new Guid(),
                                             TicketQuantity = tktQty
                                         };
     return reservation;
 }
コード例 #4
0
        public TicketReservation ReserveTicket(int tktQty)
        {
            if (!CanReserveTicket(tktQty))
            {
                ThrowExceptionWithDetailsOnWhyTicketsCannotBeReserved();
            }

            TicketReservation reservation = TicketReservationFactory.CreateReservation(this, tktQty);

            TicketReservations.Add(reservation);
            return(reservation);
        }
コード例 #5
0
        public TicketPurchase PurchaseTicketWith(Guid reservationId)
        {
            if (!CanPurchaseTicketWith(reservationId))
            {
                throw new ApplicationException(DetermineWhyTicketCannotBePurchasedWith(reservationId));
            }

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

            reservation.HasBeenRedeemed = true;

            PurchasedTickets.Add(ticket);

            return(ticket);
        }
コード例 #6
0
        public string DetermineWhyTicketCannotBePurchasedWith(Guid reservationId)
        {
            string reservationIssue = "";

            if (HasReservationWith(reservationId))
            {
                TicketReservation reservation = GetReservationWith(reservationId);;
                if (reservation.HasExpired())
                {
                    reservationIssue = String.Format("Ticket reservation no {0} has expired", reservationId);
                }
                else if (reservation.HasBeenRedeemed)
                {
                    reservationIssue = String.Format("Ticket reservation no {0} has been redeemed", reservationId);
                }
            }
            else
            {
                reservationIssue = String.Format("Ticket reservation no {0} doesn't exist", reservationId);
            }

            return(reservationIssue);
        }
コード例 #7
0
        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 conn = new SqlConnection(connectionString))
            {
                SqlCommand command = conn.CreateCommand();
                command.CommandText = queryString;

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

                conn.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;
        }