public void Pack(IEnumerable <Sandwich> package, string deliver) { /* use linq to create summary, see constructor for expectations */ Dictionary <SandwichKind, int> sums = new Dictionary <SandwichKind, int>(); foreach (var sandwich in package) { _lines[sandwich.Kind].Add(sandwich); if (sums.ContainsKey(sandwich.Kind) == false) { sums.Add(sandwich.Kind, 0); } sums[sandwich.Kind]++; } var summaryPositions = new List <LineSummary>(); foreach (var pair in sums) { summaryPositions.Add(new LineSummary(pair.Key, pair.Value)); } var summary = new PackingSummary(summaryPositions, deliver); OnPacked(summary); }
private void OnPacked(PackingSummary summary) { foreach (var summaryPosition in summary.Positions) { _lines[summaryPosition.Kind].TopUp(summaryPosition.Added); } /* add total number of added items to log statement */ Logs.Add($"{summary.TimeStamp} topped up, {summary.Vendor}."); }
private void OnPacked(PackingSummary summary) { //foreach (var summaryPosition in summary.Positions) //{ // _lines[summaryPosition.Kind].TopUp(summaryPosition.Added); //} // summary.Positions.ForEach(MyLogicForLoop); summary.Positions.ForEach(summaryPosition => _lines[summaryPosition.Kind].TopUp(summaryPosition.Added)); /* add total number of added items to log statement */ Logs.Add($"{summary.TimeStamp} topped up, {summary.Vendor}."); }
protected virtual void OnPacked(PackingSummary summary) { Packed?.Invoke(summary); }