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); }
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); }
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"); }
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); }
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); }