Beispiel #1
0
        public async Task <JourneyGetRp> GetJourneyByIdWithAvailabilities(int id, DateTime start, DateTime end)
        {
            var period = new DatePeriodValue(start, end);

            var(before, previous) = period.CalculateBeforePreviousDates();

            var entity = await this._dbContext.FullJourneyWithSourceItems(id, before.Start, end);

            if (entity == null)
            {
                return(null);
            }

            var model = this._mapper.Map <JourneyGetRp>(entity);

            foreach (var map in entity.FeatureMap)
            {
                var tmp     = this._mapper.Map <SequenceFeatureGetListRp>(map.Feature);
                var measure = map.Feature.Measure(new DatePeriodValue(start, end));
                tmp.LoadMeasure(measure);
                tmp.MapId = map.Id.Value;
                model.Features.Add(tmp);
            }

            model.LoadMeasure(entity.Measure(new DatePeriodValue(start, end)));
            model.LoadPrevious(entity.Measure(new DatePeriodValue(previous.Start, previous.End)));
            model.LoadBefore(entity.Measure(new DatePeriodValue(before.Start, before.End)));
            return(model);
        }
Beispiel #2
0
        public async Task <ProductGetListRp> GetProductsWithInformation(int customerId, DatePeriodValue period)
        {
            var products = await this._dbContext.Products.Where(c => c.CustomerId == customerId).ToListAsync();

            var(before, previous) = period.CalculateBeforePreviousDates();

            var targets = new List <ProductEntity>();

            foreach (var item in products)
            {
                targets.Add(await this._dbContext.FullLoadProductWithSourceItems(item.Id.Value, before.Start, period.End));
            }

            var squads = await this._dbContext.Squads
                         .Include(c => c.FeatureMaps)
                         .Where(c => c.CustomerId == customerId).ToListAsync();

            var features = targets.SelectMany(c => c.Features).Distinct(new FeatureEntityCompare());

            foreach (var squad in squads.SelectMany(c => c.FeatureMaps))
            {
                squad.Feature = features.Single(c => c.Id == squad.FeatureId);
            }

            foreach (var feature in targets.SelectMany(c => c.Features))
            {
                foreach (var target in feature.Squads)
                {
                    target.Squad = squads.Single(c => c.Id == target.SquadId);
                }
            }

            var models = new ProductGetListRp();

            foreach (var item in products)
            {
                var tmp = this._mapper.Map <ProductGetListItemRp>(item);
                var agg = new FeatureOwnershipAggregate(squads, item.Features);
                tmp.Ownership    = agg.Measure().assigned;
                tmp.Debt         = item.Measure(period);
                tmp.PreviousDebt = item.Measure(previous);
                tmp.BeforeDebt   = item.Measure(before);
                models.Items.Add(tmp);
            }

            return(models);
        }