private void Save(IList <CsvSpeciesStatusRating> records) { int count = 0; foreach (CsvSpeciesStatusRating record in records) { // Map the current CSV record to a conservation status rating, check it // doesn't already exist and store it in the database SpeciesStatusRating rating = SpeciesStatusRating.FromCsv(record); SpeciesStatusRating existing = _factory.Context .SpeciesStatusRatings .FirstOrDefault(r => (r.Species.Name == rating.Species.Name) && (r.Rating.Name == rating.Rating.Name) && (r.Region == rating.Region) && ((r.Start == rating.Start) || ((r.Start == null) && (rating.Start == null))) && ((r.End == rating.End) || ((r.End == null) && (rating.End == null)))); if (existing == null) { rating = _factory.SpeciesStatusRatings.Add(rating); } // Notify subscribers count++; RecordImport?.Invoke(this, new SpeciesStatusDataExchangeEventArgs { RecordCount = count, Rating = rating }); } }
private void Save(IList <CsvSighting> records) { int count = 0; foreach (CsvSighting record in records) { // Map the current CSV record to a sighting and store it in the database Sighting sighting = Sighting.FromCsv(record); sighting = _factory.Sightings.Add(sighting); // Notify subscribers count++; RecordImport?.Invoke(this, new SightingDataExchangeEventArgs { RecordCount = count, Sighting = sighting }); } }