public override List <Order> ProcessRecords(List <Record> records) { Dictionary <int, Order> ordersMap = new Dictionary <int, Order>(); MenuItemDAO menuItemDAO = new MenuItemDAO(); foreach (Record record in records) { int orderId = (int)record["OrderId"]; if (!ordersMap.ContainsKey(orderId)) { Order order = ProcessRecord(record); // 'ProcessRecords' is always available, even when it's not overriden. // In that case, it takes the records and parses them through 'ProcessRecord' order.MenuItems = menuItemDAO.ProcessRecords( records .Where(r => (int)r["OrderId"] == orderId) .ToList() ); ordersMap[orderId] = order; } } return(ordersMap.Values.ToList()); }
public override List <Menu> ProcessRecords(List <Record> records) { Dictionary <int, Menu> menuMap = new Dictionary <int, Menu>(); MenuItemDAO menuItemDAO = new MenuItemDAO(); foreach (Record record in records) { int menuId = (int)record["MenuId"]; // Check whether or not menu has been processed yet if (!menuMap.ContainsKey(menuId)) { Menu menu = ProcessRecord(record); if (record["MenuItemId"] == DBNull.Value) { menu.Items = new List <MenuItem>(); } else { // Because 'ProcessRecords' is public, we can ask other DAO's to process certain records for us menu.Items = menuItemDAO.ProcessRecords( // We only want to process the records that apply to the current menu, so we filter out any that don't // match the current menu id records .Where(r => (int)r["MenuId"] == menuId) .ToList() ); } menuMap[menuId] = menu; } } return(menuMap.Values.ToList()); }