Пример #1
0
        /// <summary>
        /// Test Find using the Query class
        /// </summary>
        private void Step_30_TestFindByQuery_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                //Insert Mock Instance
                Product mock   = CreateMockInstance(tm);
                bool    result = DataRepository.ProductProvider.Insert(tm, mock);

                Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed");

                ProductQuery query = new ProductQuery();

                query.AppendEquals(ProductColumn.ProductId, mock.ProductId.ToString());
                query.AppendEquals(ProductColumn.Name, mock.Name.ToString());
                query.AppendEquals(ProductColumn.ProductNumber, mock.ProductNumber.ToString());
                query.AppendEquals(ProductColumn.MakeFlag, mock.MakeFlag.ToString());
                query.AppendEquals(ProductColumn.FinishedGoodsFlag, mock.FinishedGoodsFlag.ToString());
                if (mock.Color != null)
                {
                    query.AppendEquals(ProductColumn.Color, mock.Color.ToString());
                }
                query.AppendEquals(ProductColumn.SafetyStockLevel, mock.SafetyStockLevel.ToString());
                query.AppendEquals(ProductColumn.ReorderPoint, mock.ReorderPoint.ToString());
                query.AppendEquals(ProductColumn.StandardCost, mock.StandardCost.ToString());
                query.AppendEquals(ProductColumn.ListPrice, mock.ListPrice.ToString());
                if (mock.Size != null)
                {
                    query.AppendEquals(ProductColumn.Size, mock.Size.ToString());
                }
                if (mock.SizeUnitMeasureCode != null)
                {
                    query.AppendEquals(ProductColumn.SizeUnitMeasureCode, mock.SizeUnitMeasureCode.ToString());
                }
                if (mock.WeightUnitMeasureCode != null)
                {
                    query.AppendEquals(ProductColumn.WeightUnitMeasureCode, mock.WeightUnitMeasureCode.ToString());
                }
                if (mock.Weight != null)
                {
                    query.AppendEquals(ProductColumn.Weight, mock.Weight.ToString());
                }
                query.AppendEquals(ProductColumn.DaysToManufacture, mock.DaysToManufacture.ToString());
                if (mock.ProductLine != null)
                {
                    query.AppendEquals(ProductColumn.ProductLine, mock.ProductLine.ToString());
                }
                if (mock.SafeNameClass != null)
                {
                    query.AppendEquals(ProductColumn.SafeNameClass, mock.SafeNameClass.ToString());
                }
                if (mock.Style != null)
                {
                    query.AppendEquals(ProductColumn.Style, mock.Style.ToString());
                }
                if (mock.ProductSubcategoryId != null)
                {
                    query.AppendEquals(ProductColumn.ProductSubcategoryId, mock.ProductSubcategoryId.ToString());
                }
                if (mock.ProductModelId != null)
                {
                    query.AppendEquals(ProductColumn.ProductModelId, mock.ProductModelId.ToString());
                }
                query.AppendEquals(ProductColumn.SellStartDate, mock.SellStartDate.ToString());
                if (mock.SellEndDate != null)
                {
                    query.AppendEquals(ProductColumn.SellEndDate, mock.SellEndDate.ToString());
                }
                if (mock.DiscontinuedDate != null)
                {
                    query.AppendEquals(ProductColumn.DiscontinuedDate, mock.DiscontinuedDate.ToString());
                }
                query.AppendEquals(ProductColumn.Rowguid, mock.Rowguid.ToString());
                query.AppendEquals(ProductColumn.ModifiedDate, mock.ModifiedDate.ToString());

                TList <Product> results = DataRepository.ProductProvider.Find(tm, query);

                Assert.IsTrue(results.Count == 1, "Find is not working correctly.  Failed to find the mock instance");
            }
        }
Пример #2
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        // get product sku from querystring
        if (Request.Params["sku"] != null)
        {
            SKU = Request.Params["sku"];
        }

        // get product num # from querystring
        if (Request.QueryString["product_num"] != null)
        {
            _productNum = Request.QueryString["product_num"];
        }

        // get quantity from querystring
        if (Request.Params["quantity"] != null)
        {
            if (!int.TryParse(Request.Params["quantity"],out _quantity))
            {
                _quantity = 1;
            }
        }

        if (SKU.Length == 0 && _productNum.Length == 0)
        {
            Response.Redirect("~/error.aspx");
            return;
        }

        if (!Page.IsPostBack)
        {
            ZNodeSKU productSKU = new ZNodeSKU();

            if (SKU.Length > 0)
            {
                productSKU = ZNodeSKU.CreateBySKU(SKU);

                if (productSKU.SKUID == 0)
                {
                    ProductService productService = new ProductService();
                    ProductQuery filters = new ProductQuery();
                    filters.AppendEquals(ProductColumn.SKU, SKU);
                    TList<Product> productList = productService.Find(filters.GetParameters());

                    if (productList != null)
                    {
                        if (productList.Count == 0)
                        {
                            // If SKUID or Invalid SKU is Zero then Redirected to default page
                            Response.Redirect("~/error.aspx");
                        }
                    }
                    else
                    {
                        // If SKUID or Invalid SKU is Zero then Redirected to default page
                        Response.Redirect("~/error.aspx");
                    }

                    ProductID = productList[0].ProductID;

                    _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID);
                }
                else
                {
                    // If SKU parameter is supplied & it has value
                    ProductID = productSKU.ProductID;

                    _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID);

                    // Set product SKU
                    _product.SelectedSKU = productSKU;
                }
            }
            else if (_productNum.Length > 0)
            {
                ProductService productService = new ProductService();
                ProductQuery filters = new ProductQuery();
                filters.AppendEquals(ProductColumn.ProductNum, _productNum);
                TList<Product> productList = productService.Find(filters.GetParameters());

                if (productList != null)
                {
                    if (productList.Count == 0)
                    {
                        // If SKUID or Invalid SKU is Zero then Redirected to default page
                        Response.Redirect("~/error.aspx");
                    }
                }
                else
                {
                    // If SKUID or Invalid SKU is Zero then Redirected to default page
                    Response.Redirect("~/error.aspx");
                }

                ProductID = productList[0].ProductID;

                _product = ZNodeProduct.Create(ProductID, ZNodeConfigManager.SiteConfig.PortalID);
            }
            else
            {
                // If SKUID or Invalid SKU is Zero then Redirected to default page
                Response.Redirect("~/error.aspx");
            }

            // Check product attributes count
            if (_product.ZNodeAttributeTypeCollection.Count > 0 && productSKU.SKUID == 0)
            {
                Response.Redirect(_product.ViewProductLink);
            }

            // Loop through the product addons
            foreach (ZNodeAddOn _addOn in _product.ZNodeAddOnCollection)
            {
                if (!_addOn.OptionalInd)
                {
                    Response.Redirect(_product.ViewProductLink);
                }
            }

            // Create shopping cart item
            ZNodeShoppingCartItem item = new ZNodeShoppingCartItem();
            item.Product = new ZNodeProductBase(_product);
            item.Quantity = _quantity;

            // Add product to cart
            ZNodeShoppingCart shoppingCart = ZNodeShoppingCart.CurrentShoppingCart();

            // If shopping cart is null, create in session
            if (shoppingCart == null)
            {
                shoppingCart = new ZNodeShoppingCart();
                shoppingCart.AddToSession(ZNodeSessionKeyType.ShoppingCart);
            }

            // add item to cart
            if (shoppingCart.AddToCart(item))
            {
                string link = "~/shoppingcart.aspx";
                Response.Redirect(link);
            }
            else
            {
                // If Product is out of Stock - Redirected to Product Details  page
                Response.Redirect("~/error.aspx");
            }
        }
    }