コード例 #1
0
ファイル: FlightRepository.cs プロジェクト: AnisYou/TUI
 public async Task Update(Flight flight)
 {
     try
     {
         context.Update(flight);
         await context.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        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);
        }