Exemple #1
0
        public override void Run(object context)
        {
            DbController           dbc      = new DbController(Connection);
            IList <BusinessObject> bObjects = new List <BusinessObject>();

            try
            {
                Connection.AutoCommit = false;
                Connection.BeginGFXDTransaction();

                Order order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.Customer = dbc.GetRandomCustomer();
                dbc.AddOrder(order);

                IList <Product> products = dbc.GetRandomProducts(5);
                foreach (Product product in products)
                {
                    OrderDetail ordDetail = new OrderDetail();
                    ordDetail.OrderId   = order.OrderId;
                    ordDetail.ProductId = product.ProductId;
                    ordDetail.UnitPrice = product.RetailPrice;
                    ordDetail.Quantity  = DbHelper.GetRandomNumber(1);
                    ordDetail.Discount  = 0;

                    dbc.AddOrderDetail(ordDetail);
                    bObjects.Add(ordDetail);

                    product.UnitsInStock -= ordDetail.Quantity;
                    dbc.UpdateProduct(product);

                    order.SubTotal += (ordDetail.UnitPrice * ordDetail.Quantity);
                }

                dbc.UpdateOrder(order);
                bObjects.Add(order);

                Connection.Commit();

                if (!dbc.ValidateTransaction(bObjects))
                {
                    Fail(dbc.GetValidationErrors(bObjects));
                }
            }
            catch (Exception e)
            {
                Connection.Rollback();
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
Exemple #2
0
        public override void Run(object context)
        {
            DbController dbc = new DbController(Connection);

            try
            {
                Order   order   = dbc.GetRandomOrder();
                Product product = dbc.GetRandomProduct();

                OrderDetail ordDetail = (OrderDetail)ObjectFactory.Create(ObjectType.OrderDetail);
                ordDetail.OrderId   = order.OrderId;
                ordDetail.ProductId = product.ProductId;
                dbc.AddOrderDetail(ordDetail);

                OrderDetail result = dbc.GetOrderDetail(ordDetail.OrderId, ordDetail.ProductId);
                if (result == null)
                {
                    Fail("Failed to insert new OrderDetail record");
                    return;
                }
                else if (!ordDetail.Equals(result))
                {
                    Fail("Inserted OrderDetail record having inconsistent data");
                    return;
                }

                ordDetail           = (OrderDetail)ObjectFactory.Create(ObjectType.OrderDetail);
                ordDetail.OrderId   = result.OrderId;
                ordDetail.ProductId = result.ProductId;
                dbc.UpdateOrderDetail(ordDetail);

                result = dbc.GetOrderDetail(ordDetail.OrderId, ordDetail.ProductId);
                if (!ordDetail.Equals(result))
                {
                    Fail("Failed to update OrderDetail record");
                    return;
                }

                dbc.DeleteOrderDetail(ordDetail.OrderId, ordDetail.ProductId);
                if (dbc.GetOrderDetail(ordDetail.OrderId, ordDetail.ProductId) != null)
                {
                    Fail("Failed to delete OrderDetail record");
                }
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
        public override void Run(object context)
        {
            DbController dbc = new DbController(Connection);

            try
            {
                Order order = dbc.GetRandomOrder();
                Product product = dbc.GetRandomProduct();

                OrderDetail ordDetail = (OrderDetail)ObjectFactory.Create(ObjectType.OrderDetail);
                ordDetail.OrderId = order.OrderId;
                ordDetail.ProductId = product.ProductId;
                dbc.AddOrderDetail(ordDetail);

                OrderDetail result = dbc.GetOrderDetail(ordDetail.OrderId, ordDetail.ProductId);
                if (result == null)
                {
                    Fail("Failed to insert new OrderDetail record");
                    return;
                }
                else if (!ordDetail.Equals(result))
                {
                    Fail("Inserted OrderDetail record having inconsistent data");
                    return;
                }

                ordDetail = (OrderDetail)ObjectFactory.Create(ObjectType.OrderDetail);
                ordDetail.OrderId = result.OrderId;
                ordDetail.ProductId = result.ProductId;
                dbc.UpdateOrderDetail(ordDetail);

                result = dbc.GetOrderDetail(ordDetail.OrderId, ordDetail.ProductId);
                if (!ordDetail.Equals(result))
                {
                    Fail("Failed to update OrderDetail record");
                    return;
                }

                dbc.DeleteOrderDetail(ordDetail.OrderId, ordDetail.ProductId);
                if (dbc.GetOrderDetail(ordDetail.OrderId, ordDetail.ProductId) != null)
                    Fail("Failed to delete OrderDetail record");
            }
            catch (Exception e)
            {
                Fail(e);
            }
            finally
            {
                base.Run(context);
            }
        }
        public override void Run(object context)
        {
            DbController dbc = new DbController(Connection);
            IList<BusinessObject> bObjects = new List<BusinessObject>();

            try
            {
                Connection.AutoCommit = false;
                Connection.BeginGFXDTransaction();

                Order order = (Order)ObjectFactory.Create(ObjectType.Order);
                order.Customer = dbc.GetRandomCustomer();
                dbc.AddOrder(order);
                
                IList<Product> products = dbc.GetRandomProducts(5);
                foreach (Product product in products)
                {
                    OrderDetail ordDetail = new OrderDetail();
                    ordDetail.OrderId = order.OrderId;
                    ordDetail.ProductId = product.ProductId;
                    ordDetail.UnitPrice = product.RetailPrice;
                    ordDetail.Quantity = DbHelper.GetRandomNumber(1);
                    ordDetail.Discount = 0;

                    dbc.AddOrderDetail(ordDetail);
                    bObjects.Add(ordDetail);

                    product.UnitsInStock -= ordDetail.Quantity;
                    dbc.UpdateProduct(product);

                    order.SubTotal += (ordDetail.UnitPrice * ordDetail.Quantity);
                }

                dbc.UpdateOrder(order);
                bObjects.Add(order);

                Connection.Commit();

                if (!dbc.ValidateTransaction(bObjects))
                    Fail(dbc.GetValidationErrors(bObjects));
            }
            catch (Exception e)
            {
                Connection.Rollback();
                Fail(e);
            }
            finally
            {                
                base.Run(context);
            }
        }