public IEnumerable <InvalidCaseReportExpanded> Get() { var invalidCaseReports = _invalidCaseReports.GetAll(); // Comment from woksin - 15/02-2018 // By fetching all dataCollectors to memory we should get reduced latency, // which was the case when I tested this method using the old method versus fetching the data prior to querying it. // In my opinion, the best way to do this is to have a cache-system for these databases (preferably in the classes that deals directly // with IMongoDatabase and IMongoCollection var dataCollectors = _dataCollectors.GetAll(); // Following over from CaseReportController... // (half -as bad, but still half-assed) // // Comment from review; einari - 23rd of October 2017 // Todo: This is a N+1 query - potentially incredibly slow // an optimization would be to get all data collectors and all healthrisks and then // do inmemory lookups. Also moved this away from being done inside the CaseReportExtended // object - as it should not be having a relationship to repositories return(invalidCaseReports.Select(caseReport => { var dataCollector = dataCollectors.FirstOrDefault(collector => collector.Id == caseReport.DataCollectorId); //var dataCollector2 = _dataCollectors.GetById(caseReport.DataCollectorId); return new InvalidCaseReportExpanded(caseReport, dataCollector); })); }
public bool PhoneNumberIsRegistered(string number) { //TODO: Maybe consider keeping a seperate phone number collection? foreach (var dataCollector in _dataCollectors.GetAll()) { foreach (var phoneNumber in dataCollector.PhoneNumbers) { if (phoneNumber.Value == number) { return(true); } } } return(false); }
public IActionResult Export(string format = "excel") { if (!exporters.ContainsKey(format)) { return(NotFound()); } var exporter = exporters[format]; var dataCollectors = _dataCollectors.GetAll(); var stream = new MemoryStream(); var result = exporter.WriteDataCollectors(dataCollectors, stream); if (result) { stream.Seek(0, SeekOrigin.Begin); return(File(stream, exporter.GetMIMEType(), "datacollectors-" + DateTimeOffset.UtcNow.ToString("yyyy-MMMM-dd") + exporter.GetFileExtension())); } stream.Close(); return(StatusCode(500)); }