Beispiel #1
0
        //internal static void RejectDuplicateName(this IStallsRepo repo, StallDTO newRecord)
        //{
        //    var matches = repo.GetAll().Where(_ => _.Name == newRecord.Name);

        //    if (matches.Any())
        //        throw DuplicateRecordsException.For(matches, nameof(newRecord.Name), newRecord.Name);
        //}


        internal static void DontDeleteIfOccupied(this IStallsRepo repo, StallDTO stall, IActiveLeasesRepo activeLses)
        {
            var lse = activeLses.GetAll().SingleOrDefault(_ => _.Stall.Id == stall.Id);

            if (lse != null)
            {
                throw Bad.Delete(stall, $"Occupied by {lse}");
            }
        }
        public static CollectorPerformanceRow New(CollectorDTO collector, IStallsRepo fallbackStallsRepo, ICollectionsDB db, IMarketStateDB mkt)
        {
            var cp       = new CollectorPerformanceRow(collector);
            var sections = db.SectionsSnapshot ?? mkt.Sections.GetAll();

            foreach (var sec in sections)
            {
                cp.AddSubRows(collector, sec, db, fallbackStallsRepo);
            }

            cp.Sections = cp.DistinctBy(_ => _.Section.Id)
                          .Select(_ => _.Section)
                          .ToList();

            cp.StallCoverage = ColPerfStallCoverage.New(cp, db);
            cp.RentBill      = ColPerfBillPerformance.New(BillCode.Rent, cp.Select(_ => _.Rent));
            cp.RightsBill    = ColPerfBillPerformance.New(BillCode.Rights, cp.Select(_ => _.Rights));

            cp.SetSummary(new CollectorPerfSubRowsTotal(cp));

            return(cp);
        }
        private void AddSubRows(CollectorDTO collector, SectionDTO sec, ICollectionsDB db, IStallsRepo stalls)
        {
            var savedCollectr = db.GetCollector(sec)
                                ?? new CollectorDTO {
                Id = 1
            };

            if (savedCollectr.Id != collector.Id)
            {
                return;
            }
            if (!db.IntendedColxns.TryGetValue(sec.Id, out IIntendedColxnsRepo repo))
            {
                return;
            }
            if (!repo.Any())
            {
                return;
            }

            foreach (var colxn in repo.GetAll())
            {
                if (colxn.StallSnapshot == null)
                {
                    colxn.StallSnapshot = stalls.Find(colxn.Lease.Stall.Id, true);
                }

                this.Add(new CollectorPerfSubRow(colxn, sec));
            }
        }