コード例 #1
0
        public override List <Reservation> ProcessRecords(List <Record> records)
        {
            Dictionary <int, Reservation> reservationMap = new Dictionary <int, Reservation>();
            OrderDAO orderDAO = new OrderDAO();

            foreach (Record record in records)
            {
                int reservationId = (int)record["ReservationId"];

                // Check whether or not reservation has been processed yet
                if (!reservationMap.ContainsKey(reservationId))
                {
                    Reservation reservation = ProcessRecord(record);

                    // Don't mind this
                    if (record["Customer"] != DBNull.Value)
                    {
                        reservation.Customer = new Customer()
                        {
                            Id   = (int)record["Customer"],
                            Name = (string)record["CustomerSurname"]
                        };
                    }

                    // We use a seperate query because joining will cause reservations without orders to be omited.
                    reservation.Orders = orderDAO.GetByReservationId(reservationId);

                    reservationMap[reservationId] = reservation;
                }
            }

            return(reservationMap.Values.ToList());
        }
コード例 #2
0
        public override List <Receipt> ProcessRecords(List <Record> records)
        {
            Dictionary <int, Receipt> receiptMap = new Dictionary <int, Receipt>();
            OrderDAO orderDAO = new OrderDAO();

            foreach (Record record in records)
            {
                int receiptId = (int)record["ReceiptId"];

                if (!receiptMap.ContainsKey(receiptId))
                {
                    Receipt receipt = ProcessRecord(record);

                    // 'ProcessRecords' is always available, even when it's not overriden.
                    // In that case, it takes the records and parses them through 'ProcessRecord'
                    receipt.Orders = orderDAO.ProcessRecords(
                        records
                        .Where(r => (int)r["ReceiptId"] == receiptId)
                        .ToList()
                        );

                    receiptMap[receiptId] = receipt;
                }
            }

            return(receiptMap.Values.ToList());
        }