public async Task <(bool Succeeded, string Error)> EditMeetAsync( int meetId, string meetName, DateTime meetDate, string meetLocation, string measurementType, CancellationToken ct) { var meet = await _context.Meets.SingleOrDefaultAsync( r => r.meetId == meetId, ct); if (meet == null) { return(false, "Meet not found"); } meet.MeetName = meetName; meet.MeetDate = meetDate; meet.MeetLocation = meetLocation; if (measurementType != meet.MeasurementType) { var events = _context.Events.Where( s => s.meetId == meet.meetId); foreach (EventEntity ee in events) { var entries = _context.Entries.Where( s => s.eventId == ee.eventId); // Remove Marks and Bar Heights if (meet.MeasurementType == "English") { RemoveEnglishMarks(entries); } else { RemoveMetricMarks(entries); } RemoveVerticalMarks(entries); foreach (EntryEntity ent in entries) { _context.Remove(ent); } } } meet.MeasurementType = measurementType; _context.Meets.Update(meet); _context.SaveChanges(); return(true, null); }
public async Task <int> UpdateLynxDataAsync( int meetId, List <LynxEvent> newEvents, List <LynxAthlete> newAthletes, CancellationToken ct) { _meetId = meetId; _newAthletes = newAthletes; _newEvents = newEvents; _oldAthletes = new Dictionary <int, int>(); _oldEvents = new Dictionary <EventKey, int>(); _oldEntries = new Dictionary <int, EventEntryEntity>(); GetOldAthletes(); AddOrUpdateAthletes(); _context.SaveChanges(); GetOldEvents(); AddOrUpdateEvents(); _context.SaveChanges(); AddOrUpdateEntries(); _context.SaveChanges(); DeleteOldEntries(); _context.SaveChanges(); DeleteOldEvents(); _context.SaveChanges(); DeleteOldAthletes(); _context.SaveChanges(); return(0); }