public async Task Delete(Guid?id) { Entities.Flight entity = await _context.Flights.FindAsync(id); if (entity != null) { _context.Flights.Remove(entity); await _context.SaveChangesAsync(); } }
private async Task <Guid?> Create(Flight flight) { Entities.Flight entity = ToEntity(flight); entity.Id = Guid.NewGuid(); _context.Add(entity); await _context.SaveChangesAsync(); return(entity.Id); }
private Flight FromEntity(Entities.Flight entity) { if (entity == null) { return(null); } return(new Flight(entity.Id, new Airport(entity.DepartureAirport.Id, entity.DepartureAirport.Name, entity.DepartureAirport.Latitude, entity.DepartureAirport.Longitude), new Airport(entity.ArrivalAirport.Id, entity.ArrivalAirport.Name, entity.ArrivalAirport.Latitude, entity.ArrivalAirport.Longitude), new Plane(entity.Plane.Id, entity.Plane.Model, entity.Plane.FuelConsumptionPer100Km, entity.Plane.TakeoffFuelConsumption))); }
private async Task <Guid?> Update(Flight flight) { Entities.Flight entity = ToEntity(flight); _context.Attach(entity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(flight.Id); } catch (DbUpdateConcurrencyException) { if (!_context.Flights.Any(e => e.Id == flight.Id)) { return(null); } else { throw; } } }