public async Task <FlightData> InsertOrUpdateFlightAsync(string id, FlightData data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } try { await flightsSm.WaitAsync().ConfigureAwait(false); var flights = await LoadAsync().ConfigureAwait(false); if (flights.TryGetValue(id, out var flight)) { flight.CopyFrom(data); } else { flight = new FlightWrapper(data) { Id = id, AddedDateTime = DateTimeOffset.UtcNow }; flights.Add(id, flight); } await SaveAsync(flights).ConfigureAwait(false); return(flight.ToDTO()); } finally { flightsSm.Release(); } }
public async Task <FlightData> AddFlightAsync(FlightData data) { try { await flightsSm.WaitAsync().ConfigureAwait(false); var flights = await LoadAsync().ConfigureAwait(false); var flight = new FlightWrapper(data) { Id = await idProvider.GenerateAsync().ConfigureAwait(false), AddedDateTime = DateTimeOffset.UtcNow }; flights.Add(flight.Id, flight); await SaveAsync(flights).ConfigureAwait(false); return(flight.ToDTO()); } finally { flightsSm.Release(); } }