示例#1
0
        public async Task <IEnumerable <InvalidCaseReportExpanded> > Get()
        {
            var invalidCaseReports = await _invalidCaseReports.GetAllAsync();

            // 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 = await _dataCollectors.GetAllAsync();

            // 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);
            }));
        }
示例#2
0
        public async Task <IActionResult> Export(string format = "excel")
        {
            if (!exporters.ContainsKey(format))
            {
                return(NotFound());
            }

            var exporter = exporters[format];

            var dataCollectors = await _dataCollectors.GetAllAsync();

            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));
        }
示例#3
0
        public async Task <IActionResult> Get()
        {
            var items = await _dataCollectors.GetAllAsync();

            return(Ok(items));
        }