private static void SaveTest(Test test) { using (var Repository = new AttemptRepository()) { SaveStatus = DatabaseSaveStatus.Saving; DataSource source = test.Attempts.First().Value.First().Source; bool success = false; try { Console.WriteLine($"Searching for {test.ID} in database..."); var testFound = Repository.Attempts.Where(z => z.ID == test.ID && z.Source == source).Count() > 0; if (testFound) { Console.WriteLine($"Test ID {test.ID} from {source} data source already exists in database"); SaveStatus = DatabaseSaveStatus.Failed; return; } Console.WriteLine($"Test ID {test.ID} not found, saving..."); foreach (var technique in DataGenerator.AllTechniques) { Repository.Attempts.AddRange(test.Attempts[technique]); } Repository.SaveChanges(); success = true; Console.WriteLine($"Successfully saved test number {test.ID} to database"); } catch (Exception e) { Console.WriteLine("Failed saving to database"); Console.WriteLine("Message: " + e.Message); } SaveStatus = success ? DatabaseSaveStatus.Success : DatabaseSaveStatus.Failed; } }
public static void UpdateAttempt(IEnumerable <Attempt> attempts) { using (var Repository = new AttemptRepository()) { foreach (var attempt in attempts) { Repository.Entry(attempt).State = EntityState.Modified; } Repository.SaveChanges(); } }
public static void InvalidateAttempts(Dictionary <string, List <int> > outliers, DataSource source) { using (var Repo = new AttemptRepository()) { foreach (var entry in outliers) { var attempts = Repo.Attempts.Where(attempt => attempt.ID == entry.Key && attempt.Source == source); foreach (var aNum in entry.Value) { var attempt = attempts.Where(att => att.AttemptNumber == aNum).Single(); attempt.Valid = false; Repo.Entry(attempt).State = EntityState.Modified; } } Repo.SaveChanges(); } }
public static void UpdateAttempt(IEnumerable<Attempt> attempts) { using (var Repository = new AttemptRepository()) { foreach (var attempt in attempts) { Repository.Entry(attempt).State = EntityState.Modified; } Repository.SaveChanges(); } }
public static void InvalidateAttempts(Dictionary<string, List<int>> outliers, DataSource source) { using(var Repo = new AttemptRepository()) { foreach (var entry in outliers) { var attempts = Repo.Attempts.Where(attempt => attempt.ID == entry.Key && attempt.Source == source); foreach(var aNum in entry.Value) { var attempt = attempts.Where(att => att.AttemptNumber == aNum).Single(); attempt.Valid = false; Repo.Entry(attempt).State = EntityState.Modified; } } Repo.SaveChanges(); } }