// Incorporate an external order into business objects public static OO.Order XmlOrder2OoOrder(XmlOns.Order o) { return(new OO.Order { Cust = OO.Customer.Lookup(o.CustId), Items = (from i in o.Item select new OO.Item { Prod = OO.Product.Lookup(i.ProdId), Price = i.Price, Quantity = i.Quantity }).ToList() }); }
// Additional preconditions on incorporation public static void Check(XmlOns.Order o) { double gain = 0; if (OO.Customer.Lookup(o.CustId) == null) { throw new OO.BizException("Unknown customer"); } foreach (var i in o.Item) { var p = OO.Product.Lookup(i.ProdId); if (p == null) { throw new OO.BizException("Unknown product"); } gain += i.Price * i.Quantity - p.Price * p.Quantity; } if (gain <= 0.0) { throw new OO.BizException("No BizCase"); } }