Ejemplo n.º 1
0
        // Mapping an business object for an order to an XmlDocument for an invoice
        public static XmlDocument OoOrder2XmlInvoice(OO.Order o)
        {
            string ns = "http://www.vertical.com/Invoice";
            var doc = new XmlDocument();

            var inv = doc.CreateElement("Invoice", ns);
            doc.AppendChild(inv);

            var name = doc.CreateElement("Name", ns);
            inv.AppendChild(name);
            name.AppendChild(doc.CreateTextNode(o.Cust.Name));

            // Ditto for street, city, zip, state

            var street = doc.CreateElement("Street", ns);
            inv.AppendChild(street);
            street.AppendChild(doc.CreateTextNode(o.Cust.Addr.Street));

            var city = doc.CreateElement("City", ns);
            inv.AppendChild(city);
            city.AppendChild(doc.CreateTextNode(o.Cust.Addr.City));

            var zip = doc.CreateElement("Zip", ns);
            inv.AppendChild(zip);
            zip.AppendChild(doc.CreateTextNode(o.Cust.Addr.Zip));

            var state = doc.CreateElement("State", ns);
            inv.AppendChild(state);
            state.AppendChild(doc.CreateTextNode(o.Cust.Addr.State));

            foreach (var i in o.Items)
            {
                var item = doc.CreateElement("Position", ns);
                inv.AppendChild(item);

                var prodid = doc.CreateElement("ProdId", ns);
                item.AppendChild(prodid);
                prodid.AppendChild(doc.CreateTextNode(i.Prod.Id));

                // Ditto for price, quantity

                var price = doc.CreateElement("Price", ns);
                item.AppendChild(price);
                price.AppendChild(doc.CreateTextNode(XmlConvert.ToString(i.Price)));

                var quantity = doc.CreateElement("Quantity", ns);
                item.AppendChild(quantity);
                quantity.AppendChild(doc.CreateTextNode(i.Quantity.ToString()));
            }

            var total = doc.CreateElement("Total", ns);
            inv.AppendChild(total);
            total.AppendChild(doc.CreateTextNode(o.Total().ToString()));

            return doc;
        }
Ejemplo n.º 2
0
 // Mapping an business object for an order to an XElement for an invoice
 public static XElement OoOrder2XmlInvoice(OO.Order o)
 {
     return new XElement(ins + "Invoice",
               new XElement(ins + "Name", o.Cust.Name),
               new XElement(ins + "Street",o.Cust.Addr.Street),
               new XElement(ins + "City",o.Cust.Addr.City),
               new XElement(ins + "Zip",o.Cust.Addr.Zip),
               new XElement(ins + "State",o.Cust.Addr.State),
               from i in o.Items
               select new XElement(ins + "Position",
                         new XElement(ins + "ProdId", i.Prod.Id),
                         new XElement(ins + "Price", i.Price),
                         new XElement(ins + "Quantity", i.Quantity)),
               new XElement(ins + "Total", o.Total()));
 }
Ejemplo n.º 3
0
 // Mapping a business object for an order to an invoice object of a schema-derived class
 public static XmlIns.Invoice OoOrder2XmlInvoice(OO.Order o)
 {
     return new XmlIns.Invoice {
         Name     = o.Cust.Name,
         Street   = o.Cust.Addr.Street,
         City     = o.Cust.Addr.City,
         Zip      = o.Cust.Addr.Zip,
         State    = o.Cust.Addr.State,
         Position =
           (from i in o.Items
            select new XmlIns.Position {
                     ProdId   = i.Prod.Id,
                     Price    = i.Price,
                     Quantity = i.Quantity }).ToList(),
         Total = o.Total() };
 }