public void Remove() { Customer theCustomer = new Customer("FIRSTNAME", "LASTNAME", "USERNAME", "PASSWORD", "ADDRESS", "PHNUMBER", "CRDNUMBER"); customerDAO.Add(theCustomer); theCustomer = customerDAO.GetAll()[0]; Country israel = new Country("Israel"); countryDAO.Add(israel); israel = countryDAO.GetAll()[0]; AirlineCompany elal = new AirlineCompany("ELAL", "ELALUSERNAME", "ELALPASSWORD", israel.ID); airlineDAO.Add(elal); elal = airlineDAO.GetAll()[0]; Flight theFlight = new Flight(elal.ID, israel.ID, israel.ID, new DateTime((DateTime.Now.Year + 2), 12, 5, 14, 00, 00), new DateTime((DateTime.Now.Year + 2), 12, 7, 14, 00, 00), 50, FlightStatus.NotDeparted); flightDAO.Add(theFlight); theFlight = flightDAO.GetAll()[0]; Ticket theTicket = new Ticket(theFlight.ID, theCustomer.ID); ticketDAO.Add(theTicket); theTicket = ticketDAO.GetAll()[0]; Assert.AreEqual(1, ticketDAO.GetAll().Count); ticketDAO.Remove(theTicket); Assert.AreEqual(null, ticketDAO.GetAll()); }
public void CancelTicket(LoginToken <Customer> token, Ticket ticket) { if (UserIsValid(token) && token.User.Id == ticket.CustomerID) { _ticketDAO.Remove(ticket); } }
// Cancel Ticket From Current Customer. public void CancelTicket(LoginToken <Customer> token, Ticket ticket) { if (UserIsValid(token) && token.User.Id == ticket.Customer_Id) { if (_flightDAO.GetById((int)ticket.Flight_Id).Departure_Time > DateTime.Now) { throw new TooLateToCancelTicketException("You Can't Cancel Your Ticket Because The Flight Has Already Begun"); } if (_flightDAO.GetById((int)ticket.Flight_Id).Departure_Time > DateTime.Now.Add(TimeSpan.FromHours(1))) { throw new TooLateToCancelTicketException("You Can't Cancel Your Ticket One Hour Before The Flight"); } _ticketDAO.Remove(ticket); } }
private void ArchiveTicketsAndFlights() { var ticketsToArchive = _ticketDAO.GetAll() .Where(t => t.Flight.LandingTime < (DateTime.Now.Subtract(TimeSpan.FromHours(3)))); var flightsToArchive = _flightDAO.GetAll() .Where(f => f.LandingTime < DateTime.Now.Subtract(TimeSpan.FromHours(3))); TicketHistory.AddRange(ticketsToArchive); FlightHistory.AddRange(flightsToArchive); foreach (var ticket in ticketsToArchive) { _ticketDAO.Remove(ticket); } foreach (var flight in flightsToArchive) { _flightDAO.Remove(flight); } }