public void GetFlightsByCustomer() { countryDAO.Add(new Country("Israel")); Country israel = countryDAO.GetCountryByName("Israel"); airlineDAO.Add(new AirlineCompany("ELAL", "ELALUSERNAME", "PASSWORD", israel.ID)); AirlineCompany elal = airlineDAO.GetAirlineByName("ELAL"); flightDAO.Add(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(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), 20, FlightStatus.NotDeparted)); customerDAO.Add(new Customer("FIRSTNAME", "LAST NAME", "USERNAME", "PASSWORD", "ADDRESS", "PHONENUMBE", "CARDNUMBER")); Customer customerTest = customerDAO.GetAll()[0]; ticketDAO.Add(new Ticket(flightDAO.GetAll()[0].ID, customerTest.ID)); ticketDAO.Add(new Ticket(flightDAO.GetAll()[1].ID, customerTest.ID)); List <Flight> customerFlights = (List <Flight>)flightDAO.GetFlightsByCustomer(customerTest); Assert.AreEqual(2, customerFlights.Count); }
// Buy New Ticket For Current Customer. public long PurchaseTicket(LoginToken <Customer> token, Flight flight) { long newId = 0; if (UserIsValid(token)) { if (flight.Remaining_Tickets > 0) { newId = _ticketDAO.Add(new Ticket { Customer_Id = token.User.Id, Flight_Id = flight.Id }); flight.Remaining_Tickets--; _flightDAO.Update(flight); } else { throw new OutOfTicketsException("Sorry But The Tickets For This Flight Is Over"); } } return(newId); }
public long PurchaseTicket(LoginToken <Customer> token, Flight flihgt) { long newId = 0; if (UserIsValid(token)) { if (flihgt.Remaining_Tickets > 0) { newId = _ticketDAO.Add(new Ticket { CustomerID = token.User.Id, FlightID = flihgt.ID }); flihgt.Remaining_Tickets--; _flightDAO.Update(flihgt); } else { throw new TicketsIsOver("Sorry To try One's Luck Next Time"); } } return(newId); }
public Ticket PurchaseTicket(LoginToken <Customer> token, Flight flight) { if (flight.Remaining_Tickets > 0) { Ticket ticket = new Ticket(flight.ID, token.User.Id); if (token != null && token.User != null) { try { ticket.ID = _ticketDAO.Add(new Ticket { CustomerID = token.User.Id, FlightID = flight.ID }); flight.Remaining_Tickets--; _flightDAO.Update(flight); } catch (Exception e) { throw new UserAlreadyExistException($"{token.User.FirstName} {token.User.LastName} already has ticket from this flight"); } return(ticket); } } throw new TicketsIsOver("Sorry To try One's Luck Next Time"); }
public void Add() { 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]; ticketDAO.Add(new Ticket(theFlight.ID, theCustomer.ID)); Assert.AreEqual(1, ticketDAO.GetAll().Count); }