示例#1
0
        public Task <Dictionary <AnomalyIdentity, List <ImageFileIdentity> > > GetImageFilesForAnomalies(IEnumerable <AnomalyIdentity> anomalyIdentities)
        {
            return(this.ExecuteInContext(async dbContext =>
            {
                var anomalyGuids = anomalyIdentities.Select(x => x.Value).ToList();

                var query = from anomaly in dbContext.Anomalies
                            where anomalyGuids.Contains(anomaly.GUID)
                            join anomalyImage in dbContext.AnomalyToImageFileMappings
                            on anomaly.ID equals anomalyImage.AnomalyID into imageGroup
                            from i in imageGroup.DefaultIfEmpty()
                            select new
                {
                    anomaly.GUID,
                    ImageIdentity = i == default ? Guid.Empty : i.ImageFileGUID,
                };

                var result = await query.ToListAsync();

                // Group it by anomaly (since we need an AnomalyInfo per AnomalyIdentity passed in)
                var grouped = result.GroupBy(
                    x => AnomalyIdentity.From(x.GUID),
                    x => ImageFileIdentity.From(x.ImageIdentity));

                var output = grouped.ToDictionary(
                    grouping => grouping.Key,
                    grouping => grouping
                    .Where(x => !x.IsEmpty())
                    .ToList());

                return output;
            }));
        }
示例#2
0
        public async Task <List <AnomalyIdentity> > GetAllAnomaliesInCatchment(CatchmentIdentity catchmentIdentity)
        {
            var anomalies = await this.ExecuteInContextAsync(async dbContext =>
            {
                var anomalyIdentityValues = await dbContext.AnomalyToCatchmentMappings.Where(x => x.CatchmentIdentity == catchmentIdentity.Value).Select(x => x.Anomaly.GUID).ToListAsync();

                var output = anomalyIdentityValues.Select(x => AnomalyIdentity.From(x)).ToList();
                return(output);
            });

            return(anomalies);
        }