/// <summary> /// 创建订单 /// </summary> /// <param name="Event"></param> /// <param name="tktQty"></param> /// <returns></returns> 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); }
public static TicketReservation CreateReservation(Event Event, int tktQty) { var reservation = new TicketReservation() { Id = Guid.NewGuid(), Event = Event, ExpiryTime = DateTime.Now.AddMinutes(1), TicketQuantity = tktQty }; return reservation; }
public static TicketReservation CreateReservation(Event e, int qty) { TicketReservation reservation = new TicketReservation() { Id = Guid.NewGuid(), Event = e, ExpiryTime = DateTime.Now.AddMinutes(1), HasBeenRedeemed = false, TicketQuantity = qty }; return(reservation); }
public TicketReservation ReserveTicket(int tktQty) { if (!CanReserveTicket(tktQty)) { ThrowExceptionWithDetailsOnWhyTicketsCannotBeReserved(); } TicketReservation reservation = TicketReservationFactory.CreateReservation(this, tktQty); ReservedTickets.Add(reservation); return(reservation); }
public TicketReservation ReserveTicket(int ticketQty) { if (!CanReserveTicket(ticketQty)) { throw new ApplicationException("no enough ticket to reserve"); } TicketReservation reservation = TicketReservationFactory.CreateReservation(this, ticketQty); //reservation.Event = this; //reservation.ExpiryTime = DateTime.Now.AddMinutes(1); //reservation.HasBeenRedeemed = false; //reservation.Id = new Guid(); //reservation.TicketQuantity = ticketQty; this.reservedTickets.Add(reservation); return(reservation); }
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 string DetermineWhyATicketCannotbePurchasedWith(Guid reservationId) { string reservationIssue = ""; if (HasReservationWith(reservationId)) { TicketReservation reservation = GetReservationWith(reservationId); if (reservation.HasExpired()) { reservationIssue = String.Format("Ticket reservation '{0}' has expired", reservationId.ToString()); } else if (reservation.HasBeenRedeemed) { reservationIssue = String.Format("Ticket reservation '{0}' has already been redeemed", reservationId.ToString()); } } else { reservationIssue = String.Format("There is no ticket reservation with the Id '{0}'", reservationId.ToString()); } return(reservationIssue); }
/// <summary> /// 根据预定票的id购买指定票 /// </summary> /// <param name="reservationId"></param> /// <returns></returns> public TicketPurchase PurchaseTicketWith(Guid reservationId) { //判断当前id的票是否已经存在于预定票务集合中 if (!CanPurchaseTicketWith(reservationId)) { //若不存在则抛出一个不能购票的异常 throw new ApplicationException(DetermineWhyATicketCannotbePurchasedWith(reservationId)); } //若存在则获取该预定的票务对象 TicketReservation reservation = GetReservationWith(reservationId); //创建购票实例 TicketPurchase ticket = TicketPurchaseFactory.CreateTicket(this, reservation.TicketQuantity); //并对预定票对象设置其可赎回属性为true 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; }