Ejemplo n.º 1
0
        public void ModifyProduct_1()
        {
            int            ExpectedOutput    = 1;
            int            GotOutput         = 0;
            ProductByStore ProductByStoreObj = new ProductByStore();

            ProductByStoreObj.SetProductByStoreID(433);
            ProductByStoreObj.SetStoreID(6);
            ProductByStoreObj.SetCategoryID(22);
            ProductByStoreObj.SetProductID(23);
            ProductByStoreObj.SetPrice(30);
            ProductByStoreObj.SetQuantity(25);
            ProductByStoreObj.SetQuantityPerUnit("test_gram");
            try
            {
                GotOutput = ProductByStoreTemplate.Update(ProductByStoreObj);
            }
            catch (Exception)
            {
                GotOutput = -2;
            }
            Assert.AreEqual(ExpectedOutput, GotOutput);
            // Modfying Product to its original values
            ProductByStoreObj.SetProductByStoreID(433);
            ProductByStoreObj.SetStoreID(5);
            ProductByStoreObj.SetCategoryID(17);
            ProductByStoreObj.SetProductID(21);
            ProductByStoreObj.SetPrice(20);
            ProductByStoreObj.SetQuantity(12);
            ProductByStoreObj.SetQuantityPerUnit("gm");
            ProductByStoreTemplate.Update(ProductByStoreObj);
        }
Ejemplo n.º 2
0
        public void AddProduct_1()
        {
            int            ExpectedOutput    = 1;
            int            GotOutput         = 0;
            ProductByStore ProductByStoreObj = new ProductByStore();

            ProductByStoreObj.SetStoreID(5);
            ProductByStoreObj.SetCategoryID(22);
            ProductByStoreObj.SetProductID(23);
            ProductByStoreObj.SetPrice(15);
            ProductByStoreObj.SetQuantity(25);
            ProductByStoreObj.SetQuantityPerUnit("test_gram");
            try
            {
                GotOutput = ProductByStore.Insert(ProductByStoreObj);
            }
            catch (Exception)
            {
                GotOutput = -2;
            }
            Assert.AreEqual(ExpectedOutput, GotOutput);
            // Deleting added Product
            List <IProductByStore> Output = ProductByStore.Select();

            foreach (ProductByStore Product in Output)
            {
                if ("test_gram" == Product.GetCategoryName())
                {
                    int CategoryID = Product.GetCategoryID();
                    ProductByStoreObj.SetProductByStoreID(CategoryID);
                    break;
                }
            }
            GotOutput = ProductByStore.Delete(ProductByStoreObj);
        }
Ejemplo n.º 3
0
 public override List <IProductByStore> Select()
 {
     Source = "sp_FetchProductByStore";
     // Product fetching stored procedure
     try
     {
         Object[] param  = null;
         DataSet  Output = Commands.ExecuteQuery(Source, CommandType.StoredProcedure, param);
         List <IProductByStore> ProductList = new List <IProductByStore>();
         foreach (DataRow dr in Output.Tables[0].Rows)
         {
             IProductByStore Product = new ProductByStore();
             Product.SetProductByStoreID(Int32.Parse(dr["pbsID"].ToString()));
             Product.SetStoreID(Int32.Parse(dr["sID"].ToString()));
             Product.SetCategoryID(Int32.Parse(dr["cID"].ToString()));
             Product.SetProductID(Int32.Parse(dr["pID"].ToString()));
             Product.SetStoreName(dr["storeName"].ToString());
             Product.SetCategoryName(dr["categoryName"].ToString());
             Product.SetProductName(dr["productName"].ToString());
             Product.SetPrice((double)dr["price"]);
             Product.SetQuantity(Int32.Parse(dr["Quantity"].ToString()));
             Product.SetQuantityPerUnit(dr["QuantityPerUnit"].ToString());
             ProductList.Add(Product);
         }
         return(ProductList);
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Ejemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            int RouteValue = int.Parse(Page.RouteData.Values["ProductID"].ToString());
            if (!Page.IsPostBack)
            {
                ErrorProduct.Visible = false;
                resultsTable.Visible = false;

                IProductByStore ProductByStoreObj = new ProductByStore();
                ProductByStoreObj.SetProductByStoreID(RouteValue);

                // build the product
                AbstractProductBuilder <ProductBuilderResponse> Builder = new ConcreteProductBuilder(ProductByStoreObj);
                Builder.BuildProductDetails();
                Builder.BuildProductImage();
                Builder.BuildLowestPriceStoreImage();
                Builder.BuildOtherStoreDetails();

                ProductBuilderResponse Response = Builder.GetFinalProduct();
                ProductButtons.InnerHtml          = " <table><tr><td><div class='row no-margin ProductAction-AddCart' id='cart_" + Response.GetProductByStoreID() + "' onclick='AddToCart(event, " + Response.GetProductByStoreID() + ", this);'><span class='pos-abs'><i class='material-icons'>add_shopping_cart</i></span><span class='pos-add-cart'>ADD TO CART</span></div></td><td><div class='row no-margin ProductAction-BuyNow' onclick='BuyNow(event, " + Response.GetProductByStoreID() + ");'><span class='pos-abs'><i class='material-icons'>shopping_cart</i></span><span class='pos-add-cart'>BUY NOW</span></div></td></tr></table>";
                Breadcrumb_Product_Name.InnerText = Response.GetProductName();
                ProductImage.InnerHtml            = " <img class='productImage' src='/assets/" + Response.GetProductImage() + "' />";
                ProductName.InnerText             = Response.GetProductName();
                ProductPriceClass.InnerHtml       = "<span>$" + Response.GetPrice().ToString() + " / " + Response.GetQuantityPerUnit() + "</span><span><img class='ProductSuperStoreImage' src='/assets/" + Response.GetStoreImage() + "' /></span>";
                ProductResult.InnerHtml           = "<a href='/Products?k=" + Response.GetCategoryName() + "'>" + Response.GetCategoryName().ToUpper() + "</a></span>";

                if (Response.GetQuantity() < 1)
                {
                    NotOutOfStockLabel.Visible = false;
                    OutOfStockLabel.Visible    = true;
                }
                else
                {
                    NotOutOfStockLabel.Visible        = true;
                    OutOfStockLabel.Visible           = false;
                    ProductQuantityDropdown.InnerHtml = GenerateDropdown(Response.GetProductByStoreID(), Response.GetQuantity());
                }

                OtherStoresProducts.InnerHtml = GenerateOtherStoreHTML(Response);
                resultsTable.Visible          = true;
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(new Fatal(), ex);
            ErrorProduct.Visible = true;
            resultsTable.Visible = false;
        }
    }
Ejemplo n.º 5
0
        public void RemoveProduct_2()
        {
            int            ExpectedOutput    = 0;
            int            GotOutput         = -1;
            ProductByStore ProductByStoreObj = new ProductByStore();

            ProductByStoreObj.SetProductByStoreID(100);
            try
            {
                GotOutput = ProductByStoreTemplate.Delete(ProductByStoreObj);
            }
            catch (Exception)
            {
                GotOutput = -2;
            }
            Assert.AreEqual(ExpectedOutput, GotOutput);
        }
Ejemplo n.º 6
0
        public void ModifyProduct_4()
        {
            int            ExpectedOutput    = -2;
            int            GotOutput         = 0;
            ProductByStore ProductByStoreObj = new ProductByStore();

            ProductByStoreObj.SetProductByStoreID(433);
            ProductByStoreObj.SetStoreID(5);
            ProductByStoreObj.SetCategoryID(-1);
            ProductByStoreObj.SetProductID(23);
            ProductByStoreObj.SetPrice(30);
            ProductByStoreObj.SetQuantity(25);
            ProductByStoreObj.SetQuantityPerUnit("test_gram");
            try
            {
                GotOutput = ProductByStoreTemplate.Update(ProductByStoreObj);
            }
            catch (Exception)
            {
                GotOutput = -2;
            }
            Assert.AreEqual(ExpectedOutput, GotOutput);
        }
Ejemplo n.º 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ApiResponse = APIResponse.NOT_OK;
        int         Quantity    = 0;
        Cart        CartObj     = new Cart();

        try
        {
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                foreach (CartItems Items in CartObj.CartItems)
                {
                    IProductByStore PBSObj = new ProductByStore();
                    PBSObj.SetProductByStoreID(Items.ProductObj.pbsID);
                    Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj);
                    if (GetMaxQty < DBProductQty.Quantity)
                    {
                        Items.DBQuantity = GetMaxQty;
                    }
                    else
                    {
                        Items.DBQuantity = DBProductQty.Quantity;
                    }
                    if (Items.ProductObj.Quantity < 0)
                    {
                        CartObj.HasValidationErrors = true;
                        Items.ProductObj.Quantity   = -1;
                        Items.HasQuantity           = false;
                    }
                    else
                    if (DBProductQty.Quantity < Items.ProductObj.Quantity && Items.ProductObj.Quantity <= 0)
                    {
                        CartObj.HasValidationErrors = true;
                        Items.ProductObj.Quantity   = -1;
                        Items.HasQuantity           = false;
                    }
                    else if (DBProductQty.Quantity < Items.ProductObj.Quantity)
                    {
                        CartObj.HasValidationErrors = true;
                        Items.HasQuantity           = false;
                    }
                    Quantity = CartObj.CartItems.Count;
                }
            }
            ApiResponse = APIResponse.OK;
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ApiResponse = APIResponse.NOT_OK;
        }
        finally
        {
            var Cart = new
            {
                Response = ApiResponse.ToString(),
                Quantity,
                Cart = new JavaScriptSerializer().Serialize(CartObj)
            };
            Response.Write(new JavaScriptSerializer().Serialize(Cart));
        }
    }
Ejemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ResponseENUM   = APIResponse.NOT_OK;
        string      ResponseString = "";

        try
        {
            Cart CartObj = null;
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                int PBSId = int.Parse(Request.Form["pbsid"].ToString());
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                int Iterator = 0;
                foreach (CartItems Cart in CartObj.CartItems)
                {
                    if (Cart.ProductObj.pbsID == PBSId)
                    {
                        int             Quantity = int.Parse(Request.Form["qty"].ToString());
                        IProductByStore PBSObj   = new ProductByStore();
                        PBSObj.SetProductByStoreID(PBSId);
                        Products DBProductQty = new ProductByStoreBusinessLayerTemplate().Select(PBSObj);
                        if (Quantity <= DBProductQty.Quantity)
                        {
                            Cart.ProductObj.Quantity = Quantity;
                            ResponseENUM             = APIResponse.OK;
                            ResponseString           = "SUCCESS";
                        }
                        else
                        {
                            Cart.ProductObj.Quantity = Quantity;
                            ResponseENUM             = APIResponse.NOT_OK;
                            ResponseString           = "CURRENT QUANTITY NOT AVAILABLE, PLEASE REFRESH THE PAGE TO SEE UPDATED QUANTITY";
                        }
                        break;
                    }
                    Iterator += 1;
                }
                CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
            }
            else
            {
                ResponseENUM   = APIResponse.NOT_OK;
                ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES";
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseENUM   = APIResponse.NOT_OK;
            ResponseString = "AN ERROR OCCURED WHILE READING THE CART, PLEASE CLEAR YOUR COOKIES";
        }
        finally
        {
            var ReturnObj = new
            {
                Response = ResponseENUM.ToString(),
                ResponseString
            };
            Response.Write(new JavaScriptSerializer().Serialize(ReturnObj));
        }
    }
Ejemplo n.º 9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        APIResponse ResponseENUM   = APIResponse.NOT_OK;
        string      ResponseString = "";

        try
        {
            Cart CartObj = null;
            if (CookieProxy.Instance().HasKey("Cart"))
            {
                int PBSId = int.Parse(Request.Form["pbsid"].ToString());
                CartObj = new JavaScriptSerializer().Deserialize <Cart>(CookieProxy.Instance().GetValue("Cart").ToString());
                bool AlreadyHasProductInCart = false;
                foreach (CartItems Cart in CartObj.CartItems)
                {
                    if (Cart.ProductObj.pbsID == PBSId)
                    {
                        ResponseENUM            = APIResponse.NOT_OK;
                        ResponseString          = "PRODUCT ALREADY ADDED TO CART, PLEASE MODIFY THE QUANTITY";
                        AlreadyHasProductInCart = true;
                        break;
                    }
                }
                if (AlreadyHasProductInCart == false)
                {
                    ProductByStore PBSPbj = new ProductByStore();
                    PBSPbj.SetProductByStoreID(PBSId);
                    CartItems CartItemsObj = new CartItems
                    {
                        HasQuantity = true,
                        ProductObj  = new ProductByStoreBusinessLayerTemplate().Select(PBSPbj)
                    };
                    // reset the quantity to 1, we want the user quantity not the product quantity
                    CartItemsObj.ProductObj.Quantity = 1;
                    CartObj.CartItems.Add(CartItemsObj);
                    CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
                    ResponseENUM   = APIResponse.OK;
                    ResponseString = "SUCCESS";
                }
            }
            else
            {
                CartObj = new Cart
                {
                    CartItems = new List <CartItems>()
                };
                int       PBSId        = int.Parse(Request.Form["pbsid"].ToString());
                CartItems CartItemsObj = new CartItems
                {
                    HasQuantity = true,
                    ProductObj  = new ProductByStoreBusinessLayerTemplate().Select(new ProductByStore()
                    {
                        ProductByStoreID = PBSId
                    })
                };
                // reset the quantity to 1, we want the user quantity (user has initially selected the quantity) not the product quantity
                CartItemsObj.ProductObj.Quantity = 1;
                CartObj.CartItems.Add(CartItemsObj);
                CookieProxy.Instance().SetValue("Cart", new JavaScriptSerializer().Serialize(CartObj), DateTime.Now.AddDays(5));
                ResponseENUM   = APIResponse.OK;
                ResponseString = "SUCCESS";
            }
        }
        catch (Exception ex)
        {
            Logger.Instance().Log(Warn.Instance(), ex);
            ResponseENUM   = APIResponse.NOT_OK;
            ResponseString = "ERROR";
        }
        finally
        {
            var ReturnObj = new
            {
                Response = ResponseENUM.ToString(),
                ResponseString
            };
            Response.Write(new JavaScriptSerializer().Serialize(ReturnObj));
        }
    }