Example #1
0
        public void AttachWithChildExistingTest()
        {
            var orderBo = new busOrder();
            var custBo  = new busCustomer(orderBo); // share context

            // same as this to share context
            //custBo.Context = orderBo.Context;

            var order = orderBo.NewEntity();

            order.OrderId = StringUtils.NewStringId();

            // this is easiest and most efficient - if you have a PK
            //order.CustomerPk = 1;

            // manually load customer instance from context
            var cust = custBo.Load(1);

            cust.Updated = DateTime.Now; // make a change

            // assign the customer
            order.Customer = cust;

            // add a new line item
            order.LineItems.Add(new LineItem()
            {
                Description = "Cool new Item",
                Price       = 40M,
                Sku         = "COOLNEW",
                Quantity    = 1,
                Total       = 40m
            });

            Assert.IsTrue(orderBo.Save(), orderBo.ErrorMessage);
        }
Example #2
0
        public void AttachWithChildExistingAndCustIdTest()
        {
            var orderBo = new busOrder();

            var order = orderBo.NewEntity();

            order.OrderId = StringUtils.NewStringId();

            // this is easiest and most efficient
            order.CustomerPk = 1;

            // add a new line item
            order.LineItems.Add(new LineItem()
            {
                Description = "Cool new Item",
                Price       = 40M,
                Sku         = "COOLNEW",
                Quantity    = 1,
                Total       = 40m
            });

            Assert.IsTrue(orderBo.Save(), orderBo.ErrorMessage);
        }