Ejemplo n.º 1
0
        private SectionDTO FindSection(ReportModels.Stall byf)
        {
            var secId = (int)byf.Section.Id.Value;
            var sec   = AppArgs.MarketState.Sections.Find(secId, false);

            if (sec == null)
            {
                throw No.Match <SectionDTO>("Id", secId);
            }

            return(sec);
        }
Ejemplo n.º 2
0
        private T FindById <T>(int recId, Dictionary <int, T> dict, bool errorIfNoMatch)
        {
            var found = dict.TryGetValue(recId, out T dto);

            if (found)
            {
                return(dto);
            }
            if (!errorIfNoMatch)
            {
                return(default(T));
            }
            throw No.Match <T>("Id", recId);
        }
Ejemplo n.º 3
0
        public static StallDTO PickFirstVacant(MarketStateDbBase mkt)
        {
            var vm = new StallPickerVM(mkt, null);

            foreach (var sec in vm.Sections)
            {
                vm.PickedSection = sec;
                if (vm.Stalls.Any())
                {
                    return(vm.Stalls.First());
                }
            }
            throw No.Match <StallDTO>("state", "vacant");
        }
Ejemplo n.º 4
0
        public CollectorDTO CollectorByName(string collectorName, bool errorIfNoMatch = true)
        {
            var matches = _colctrsById.Values.Where(_ => _.Name == collectorName);

            if (matches.Count() == 1)
            {
                return(matches.First());
            }
            if (matches.Count() > 1)
            {
                DuplicateRecordsException.For(matches, "Name", collectorName);
            }

            if (!errorIfNoMatch)
            {
                return(null);
            }
            throw No.Match <CollectorDTO>("Name", collectorName);
        }
Ejemplo n.º 5
0
        private static List <JournalVoucherDTO> CastAsAllByfs(List <dynamic> byfHeadrs, List <dynamic> byfItems, MainWindowVM2 main)
        {
            var headrs    = byfHeadrs.Select(_ => (JournalVoucherDTO)CastAsVoucherDTO(_)).ToList();
            var itemsDict = GroupItemsByHeader(byfItems, main.RntCache);

            foreach (var kvp in itemsDict)
            {
                var headr = headrs.SingleOrDefault(_ => _.Id == kvp.Key);
                if (headr == null)
                {
                    throw No.Match <JournalVoucherDTO>("Id", kvp.Key);
                }

                if (!headr.IsBalanced)
                {
                    throw Bad.State <JournalVoucherDTO>("balanced", "not balanced");
                }

                headr.Allocations = kvp.Value;
                headr.Amount      = headr.TotalCredit;
            }
            return(headrs);
        }