public int CompareTo(Ticket otherTicket) { int compareToResult = this.DateAndTime.CompareTo(otherTicket.DateAndTime); if (compareToResult == 0) { compareToResult = this.Type.CompareTo(otherTicket.Type); } if (compareToResult == 0) { compareToResult = this.Price.CompareTo(otherTicket.Price); } return compareToResult; }
private string DeleteTicket(Ticket ticket) { string key = ticket.UniqueKey; if (this.ticketesByUniqueKey.ContainsKey(key)) { ticket = this.ticketesByUniqueKey[key]; this.ticketesByUniqueKey.Remove(key); string fromToKey = ticket.FromToKey; this.ticketsByFromToKey.Remove(fromToKey, ticket); this.ticketsByDate.Remove(ticket.DateAndTime, ticket); return "Ticket deleted"; } else { return "Ticket does not exist"; } }
private string AddTicket(Ticket ticket) { string key = ticket.UniqueKey; if (this.ticketesByUniqueKey.ContainsKey(key)) { return "Duplicate ticket"; } else { this.ticketesByUniqueKey.Add(key, ticket); string fromToKey = ticket.FromToKey; this.ticketsByFromToKey.Add(fromToKey, ticket); this.ticketsByDate.Add(ticket.DateAndTime, ticket); return "Ticket added"; } }