public async Task Update(Flight flight) { try { context.Update(flight); await context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } }
public int EditFlight(int id, string departureLocation, string landingLocation, DateTime departureDateTime, DateTime landingDatetime, string planeType, string planeUniqueId, string pilotName, int regularSeats, int businessSeats) { if (departureLocation == landingLocation) { return(-1); //both locations cant be the same } if (DateTime.Compare(departureDateTime, landingDatetime) > 0) { return(-2); //the departure cant be ahead of the landing } var testFlight = context.Flights.FirstOrDefault(x => x.PlaneUniqueId == planeUniqueId); if (testFlight != null && testFlight.Id != id) { return(-3); //the plane id should be unique } var flight = context.Flights.Find(id); flight.Id = id; flight.DepartureLocation = departureLocation; flight.LandingLocation = landingLocation; flight.DepartureDateTime = departureDateTime; flight.LandingDateTime = landingDatetime; flight.PlaneType = planeType; flight.PlaneUniqueId = planeUniqueId; flight.PilotName = pilotName; flight.RegularSeats = regularSeats; flight.BusinessSeats = businessSeats; context.Update(flight); context.SaveChanges(); return(flight.Id); }