public void MapFlightToETest() { l.Flight flight1 = new l.Flight { FlightID = 1, Company = "AA", DepartureTime = new DateTime(2010, 1, 1), ArrivalTime = new DateTime(2010, 1, 2), Origin = "DAL", Destination = "LAX", SeatAvailable = 123, Price = 299.99 }; d.Flight flight2 = d.Mapper.MapFlightToE(flight1); Assert.Equal(flight1.FlightID, flight2.FlightID); Assert.Equal(flight1.Company, flight2.Company); Assert.Equal(flight1.DepartureTime, flight2.DepartureTime); Assert.Equal(flight1.ArrivalTime, flight2.ArrivalTime); Assert.Equal(flight1.Origin, flight2.Origin); Assert.Equal(flight1.Destination, flight2.Destination); Assert.Equal(flight1.SeatAvailable, flight2.SeatAvailable); Assert.Equal(flight1.Price, flight2.Price); }
public async Task <IActionResult> Delete(int id) { Logic.Flight fli = new Logic.Flight(); fli.FlightID = id; await iRepo.DeleteFlight(fli); return(Ok()); }
public async Task <string> CreateFlight(Logic.Flight flight) { Flight e_flight = Mapper.MapFlightToE(flight); dbcontext.Add(e_flight); await dbcontext.SaveChangesAsync(); //logger.info(); return("New Flight Created!"); }
public async Task <string> DeleteFlight(Logic.Flight flight) { Flight e_flight = await dbcontext.Flight.FindAsync(flight.FlightID); if (e_flight == null) { //logger.Warn("Flight not found.") return("no such customer"); } dbcontext.Remove(dbcontext.Flight.Find(flight.FlightID)); await dbcontext.SaveChangesAsync(); //logger.info(); return("delete success"); }
public async Task <string> UpdateFlight(Logic.Flight flight) { Flight e_flight = await dbcontext.Flight.FindAsync(flight.FlightID); if (e_flight == null) { //logger.Warn("Flight not Found") return("no such Flight"); } if (flight.Company != null) { e_flight.Company = flight.Company; } if (flight.Origin != null) { e_flight.Origin = flight.Origin; } if (flight.Destination != null) { e_flight.Destination = flight.Destination; } if (flight.DepartureTime != null) { e_flight.DepartureTime = flight.DepartureTime; } if (flight.ArrivalTime != null) { e_flight.ArrivalTime = flight.ArrivalTime; } if (flight.SeatAvailable > 0) { e_flight.SeatAvailable = flight.SeatAvailable; } if (flight.Price > 0) { e_flight.Price = flight.Price; } await dbcontext.SaveChangesAsync(); //logger.Info(); return("update success"); }
public async Task <ActionResult> Post([FromBody, Bind("Company, DepartureTime, ArrivalTime, Origin, Destination, SeatAvailable, Price")] API.Models.APIFlight flight) { Logic.Flight fli = new Logic.Flight { FlightID = flight.FlightID, Company = flight.Company, DepartureTime = flight.DepartureTime, ArrivalTime = flight.ArrivalTime, Origin = flight.Origin, Destination = flight.Destination, SeatAvailable = flight.SeatAvailable, Price = flight.Price }; await iRepo.CreateFlight(fli); return(CreatedAtRoute("GetFlight", new { id = fli.FlightID }, fli)); }
public async Task <IEnumerable <API.Models.APIFlight> > Get(int id) { Logic.Flight LFlight = new Logic.Flight(); LFlight.FlightID = id; //Will add another method to check max element of FlightID if (LFlight.FlightID <= 0 || LFlight.FlightID > await iRepo.GetFlightId()) { IEnumerable <Logic.Flight> allFlights = await iRepo.ReadFlightList(null); IEnumerable <API.Models.APIFlight> nullAPI = allFlights.Select(af => new API.Models.APIFlight { FlightID = af.FlightID, Company = af.Company, DepartureTime = af.DepartureTime, ArrivalTime = af.ArrivalTime, Origin = af.Origin, Destination = af.Destination, SeatAvailable = af.SeatAvailable, Price = af.Price }); return(nullAPI); } IEnumerable <Logic.Flight> flights = await iRepo.ReadFlightList(LFlight); IEnumerable <API.Models.APIFlight> apiFlights = flights.Select(f => new API.Models.APIFlight { FlightID = f.FlightID, Company = f.Company, DepartureTime = f.DepartureTime, ArrivalTime = f.ArrivalTime, Origin = f.Origin, Destination = f.Destination, SeatAvailable = f.SeatAvailable, Price = f.Price }); return(apiFlights); }
public async Task <IActionResult> Put([FromBody] API.Models.APIFlight AFlight) { Logic.Flight fli = new Logic.Flight(); IEnumerable <Logic.Flight> Lflights = await iRepo.ReadFlightList(fli); Logic.Flight newFli = new Logic.Flight { FlightID = AFlight.FlightID, Company = AFlight.Company, DepartureTime = AFlight.DepartureTime, ArrivalTime = AFlight.ArrivalTime, Origin = AFlight.Origin, Destination = AFlight.Destination, SeatAvailable = AFlight.SeatAvailable, Price = AFlight.Price }; await iRepo.UpdateFlight(newFli); return(Ok()); }
public async Task <List <Logic.Flight> > ReadFlightList(Logic.Flight flight) { if (flight == null) { List <Flight> flightFind = await dbcontext.Flight.ToListAsync(); return(flightFind.Select(Mapper.MapEtoFlight).ToList()); } if (flight.FlightID <= 0) { IQueryable <Flight> e_flight = dbcontext.Flight; if (flight.Company != null) { e_flight = e_flight.Where(f => f.Company == flight.Company) .AsNoTracking(); } if (flight.DepartureTime != null) { e_flight = e_flight.Where(f => f.DepartureTime == flight.DepartureTime) .AsNoTracking(); } if (flight.ArrivalTime != null) { e_flight = e_flight.Where(f => f.ArrivalTime == flight.ArrivalTime) .AsNoTracking(); } if (flight.Origin != null) { e_flight = e_flight.Where(e => e.Origin == flight.Origin) .AsNoTracking(); } if (flight.Destination != null) { e_flight = e_flight.Where(e => e.Destination == flight.Destination) .AsNoTracking(); } if (flight.SeatAvailable > 0) { e_flight = e_flight.Where(f => f.SeatAvailable == flight.SeatAvailable) .AsNoTracking(); } if (flight.Price > 0) { e_flight = e_flight.Where(f => f.Price == flight.Price) .AsNoTracking(); } List <Flight> flightFind = await e_flight.ToListAsync(); List <Logic.Flight> resultFlight = flightFind.Select(Mapper.MapEtoFlight).ToList(); if (resultFlight.Count < 1) { //logger.Warn(); return(null); } return(resultFlight); } else { List <Logic.Flight> flightFind = new List <Logic.Flight> { Mapper.MapEtoFlight(await dbcontext.Flight.FindAsync(flight.FlightID)) }; //logger.Info(); return(flightFind); } }