private void RemoveIncompleteStatsIfAny(IEFStatRepository _statsRepo) { List <DailyStatisticsModel> statsToBeRemoved = _statsRepo.GetAllStatsForToday(); if (statsToBeRemoved.Count > 0) { _statsRepo.DeleteStats(statsToBeRemoved); } }
public bool CheckIfStatsCompleteForToday() { using (IServiceScope scope = _scopeFactory.CreateScope()) { IEFStatRepository _statsRepo = scope.ServiceProvider.GetRequiredService <EFStatRepository>(); return(_statsRepo.AreCompleteStatsForToday()); }; }
//todo: unit tests public void UpdateDailyStatistics() { List <string> vesselCategories = new List <string>() { "Cargo", "Dredging", "Fishing", "Offshore", "Other", "Passenger", "Tanker", "Tug" }; List <string> areaNames = GetSeaAreas().Select(a => a.Name).ToList(); using (IServiceScope scope = _scopeFactory.CreateScope()) { IEFStatRepository _statsRepo = scope.ServiceProvider.GetRequiredService <EFStatRepository>(); RemoveIncompleteStatsIfAny(_statsRepo); for (int i = 0; i < vesselCategories.Count(); i++) { for (int j = 0; j < areaNames.Count(); j++) { if (areaNames[j] != "Unknown") { DailyStatisticsModel updateStats = new DailyStatisticsModel() { Date = DateTime.UtcNow, Moving = _statsRepo.GetMoving(areaNames[j], vesselCategories[i]), Moored = _statsRepo.GetMoored(areaNames[j], vesselCategories[i]), Anchored = _statsRepo.GetAnchored(areaNames[j], vesselCategories[i]), VesselCategory = vesselCategories[i], Area = areaNames[j] }; _statsRepo.SaveStatistics(updateStats); } } } }; }