Esempio n. 1
0
        private IEnumerable<InvoiceBaseWrapper> ToListInvoiceBaseWrappers(ICollection<Invoice> items)
        {
            if (items == null || items.Count == 0) return new List<InvoiceWrapper>();

            var result = new List<InvoiceBaseWrapper>();


            var contactIDs = items.Select(item => item.ContactID);
            contactIDs.ToList().AddRange(items.Select(item => item.ConsigneeID));

            var contacts = DaoFactory.GetContactDao().GetContacts(contactIDs.Distinct().ToArray())
                                     .ToDictionary(item => item.ID, ToContactBaseWithEmailWrapper);


            foreach (var invoice in items)
            {
                var invoiceWrapper = new InvoiceBaseWrapper(invoice);

                if (contacts.ContainsKey(invoice.ContactID))
                {
                    invoiceWrapper.Contact = contacts[invoice.ContactID];
                }

                if (contacts.ContainsKey(invoice.ConsigneeID))
                {
                    invoiceWrapper.Consignee = contacts[invoice.ContactID];
                }

                if (invoice.EntityID > 0)
                {
                    invoiceWrapper.Entity = ToEntityWrapper(invoice.EntityType, invoice.EntityID); //Need to optimize
                }

                invoiceWrapper.Cost = invoice.GetInvoiceCost();

                result.Add(invoiceWrapper);
            }

            return result;
        }
Esempio n. 2
0
        private InvoiceBaseWrapper ToInvoiceBaseWrapper(Invoice invoice)
        {
            var result = new InvoiceBaseWrapper(invoice);

            if (invoice.ContactID > 0)
            {
                result.Contact = ToContactBaseWithEmailWrapper(DaoFactory.GetContactDao().GetByID(invoice.ContactID));
            }

            if (invoice.ConsigneeID > 0)
            {
                result.Consignee = ToContactBaseWithEmailWrapper(DaoFactory.GetContactDao().GetByID(invoice.ConsigneeID));
            }

            if (invoice.EntityID > 0)
            {
                result.Entity = ToEntityWrapper(invoice.EntityType, invoice.EntityID);
            }

            result.Cost = invoice.GetInvoiceCost();

            return result;
        }