Exemplo n.º 1
0
 /* Obtain all the custom brick models which admin has set it to show */
 public IQueryable<Brick> GetBricks()
 {
     var _db = new ZVerseBrickProject.Models.ProductContext();
     IQueryable<Brick> query = _db.Bricks;
     query = query.Where(b => b.isVisible == true);
     return query;
 }
Exemplo n.º 2
0
        public int AddBrick(int pid, string BrickName, string BrickDesc, string BrickIncript, string BrickPrice, string BrickImagePath, string BrickJSPath, bool BrickIsVisible, string Brickshowhide , bool BrickisStandard, string text1, string text2, string text3)
        {
            //Debug.WriteLine("addbrick: js path is " + BrickJSPath);
            //Debug.WriteLine("addbrick: showhide is " + Brickshowhide);

            var myBrick = new Brick();
            //myBrick.BrickID = BrickID;
            myBrick.pid = pid;
            myBrick.BrickName = BrickName;
            myBrick.Description = BrickDesc;
            myBrick.Incription = BrickIncript;
            myBrick.UnitPrice = Convert.ToDouble(BrickPrice);
            myBrick.ImagePath = BrickImagePath;
            myBrick.JSPath = BrickJSPath;
            myBrick.isVisible = BrickIsVisible;
            myBrick.showhide = Brickshowhide;
            myBrick.isStandard = BrickisStandard;
            myBrick.tb1 = text1;
            myBrick.tb2 = text2;
            myBrick.tb3 = text3;

            using (ProductContext _db = new ProductContext())
            {
                _db.Bricks.Add(myBrick);
                _db.SaveChanges();
            }

            int id = myBrick.BrickID;
            return id;
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
 }
Exemplo n.º 4
0
 /* Obtain all the products in the database. If category is selected ,
 obtain only products within that school category */
 public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
 {
     var _db = new ZVerseBrickProject.Models.ProductContext();
     IQueryable<Product> query = _db.Products;
     if (categoryId.HasValue && categoryId > 0)
     {
         query = query.Where(p => p.ProductID < 16 && p.CategoryID == categoryId);
     }
     else
     {
         query = query.Where(p => p.ProductID < 16);
     }
     return query;
 }
Exemplo n.º 5
0
        protected void RemoveBrick(object sender, CommandEventArgs e)
        {
            int brickid = Int32.Parse(e.CommandArgument.ToString());
            var _db = new ZVerseBrickProject.Models.ProductContext();
            Brick thebrick;
            Product theproduct;
            thebrick = _db.Bricks.Find(brickid);
            theproduct = _db.Products.Find(thebrick.pid);

            _db.Bricks.Remove(thebrick);
            _db.Products.Remove(theproduct);
            _db.SaveChanges();
            Response.Redirect("AdminPage.aspx", false);
            Context.ApplicationInstance.CompleteRequest();
        }
Exemplo n.º 6
0
        public IQueryable<Brick> GetBrick([QueryString("brickID")] int? brickId)
        {
            var _db = new ZVerseBrickProject.Models.ProductContext();
            IQueryable<Brick> query = _db.Bricks;
            //query = query.Where(p => p.BrickID == 1);
            if (brickId.HasValue && brickId > 0)
            {
                query = query.Where(p => p.BrickID == brickId);

            }
            else
            {
                query = null;
            }
            //Debug.Write("query: " + query);

            return query;
        }
Exemplo n.º 7
0
        public int AddProduct(string ProductName, string ProductDesc, string ProductPrice, string ProductCategory, string ProductImagePath, string ProductIncript)
        {
            var myProduct = new Product();
            myProduct.ProductName = ProductName;
            myProduct.Description = ProductDesc;
            myProduct.UnitPrice = Convert.ToDouble(ProductPrice);
            myProduct.ImagePath = ProductImagePath;
            myProduct.CategoryID = Convert.ToInt32(ProductCategory);
            myProduct.Incription = ProductIncript;

            using (ProductContext _db = new ProductContext())
            {
                _db.Products.Add(myProduct);
                _db.SaveChanges();
            }

            int id = myProduct.ProductID;
            return id;
        }
Exemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int productId;
            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
            {
                int currentID = Convert.ToInt16(rawId);

                //create new product and brick model if it is a custom model
                if((currentID < 0))
                {
                    string text1 = Request.QueryString["tb1"];
                    string text2 = Request.QueryString["tb2"];
                    string text3 = Request.QueryString["tb3"];
                    string incription = string.Concat(text1, " ", text2, " ", text3);
                    var _db = new ZVerseBrickProject.Models.ProductContext();
                    Brick theproduct;
                    AddProducts products = new AddProducts();
                    AddBricks bricks = new AddBricks();
                    bool isStandard = false;
                    bool isVisible = false;

                    theproduct = _db.Bricks.Find(-currentID);
                    //Debug.WriteLine("add to cart: js path is " + theproduct.JSPath);
                    currentID = products.AddProduct(theproduct.BrickName, theproduct.Description,theproduct.UnitPrice.ToString(), "1", theproduct.ImagePath, incription);
                    bricks.AddBrick(currentID, theproduct.BrickName, theproduct.Description, incription, theproduct.UnitPrice.ToString(), theproduct.ImagePath, theproduct.JSPath, isVisible, "show", isStandard, text1, text2, text3);

                }

                using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
                {
                    usersShoppingCart.AddToCart(currentID);
                }

            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.");
            }
            Response.Redirect("ShoppingCart.aspx", false);
            Context.ApplicationInstance.CompleteRequest();
        }
Exemplo n.º 9
0
        //This function will set the brickmodel visible property to
        // be false to hide the model from tab and catalogue
        //protected void Hide_Click(object sender, CommandEventArgs e)
        //{
        //    int brickid = Int32.Parse(e.CommandArgument.ToString());
        //    var _db = new ZVerseBrickProject.Models.ProductContext();
        //    //does not work
        //    ListView bricklistivew = (ListView)Master.FindControl("bricklist");
        //    Debug.Print("bricklistivew: " + bricklistivew.ToString());
        //foreach (ListViewDataItem qsnItem in bricklistivew.Items)
        //{
        //    try {
        //        Debug.Print("each item " + qsnItem.ToString());
        //        Panel p = (Panel)qsnItem.FindControl("Panel" + brickid);
        //        Debug.Print(p.ToString());
        //        p.Visible = false;
        //    }
        //    catch (Exception ex)
        //    {
        //        Debug.Print("error message" + ex.Message);
        //    }
        //}
        //foreach (ListViewItem item in bricklistivew.Items)
        //{
        //    if (item.ItemType == ListViewItemType.DataItem)
        //    {
        //        try
        //        {
        //            Panel p = (Panel)item.FindControl("Panel" + brickid);
        //            p.Visible = false;
        //        }
        //        catch (Exception ex)
        //        {
        //            StatusLabel.Text = "Task could not be completed, the following error occured: " + ex.Message;
        //        }
        //    }
        //}
        //    Brick thebrick;
        //    thebrick = _db.Bricks.Find(brickid);
        //    thebrick.isVisible = false;
        //    _db.SaveChanges();
        //    Response.Redirect("AdminPage.aspx");
        //}
        //This function will set the brickmodel visible property to
        // be true to reveal the model on the tab and catalogue.
        protected void Show_Click(object sender, CommandEventArgs e)
        {
            int brickid = Int32.Parse(e.CommandArgument.ToString());
            var _db = new ZVerseBrickProject.Models.ProductContext();
            Brick thebrick;
            thebrick = _db.Bricks.Find(brickid);

            //toggle the visibility property
            if (thebrick.isVisible)
            {
                thebrick.showhide = "Hide";
                thebrick.isVisible = false;
            }
            else
            {
                thebrick.showhide = "Show";
                thebrick.isVisible = true;
            }
            _db.SaveChanges();
            Response.Redirect("AdminPage.aspx");
        }
Exemplo n.º 10
0
        protected void lv_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("testbrick"))
            {
                //TextBox t = bricklist.Items[Convert.ToInt32(e.CommandArgument)].FindControl("brickid") as TextBox;
                TextBox brickid = e.Item.FindControl("brickid") as TextBox;
                TextBox brickname = e.Item.FindControl("brickname") as TextBox;
                TextBox brickprice = e.Item.FindControl("brickprice") as TextBox;

                Debug.Print(brickid.Text + " " + brickname.Text + " " + brickprice.Text);
                int bid = Int32.Parse(brickid.Text);
                var _db = new ZVerseBrickProject.Models.ProductContext();
                Brick thebrick;
                thebrick = _db.Bricks.Find(bid);
                thebrick.BrickName = brickname.Text;
                thebrick.UnitPrice = Double.Parse(brickprice.Text);
                _db.SaveChanges();
                Response.Redirect("AdminPage.aspx", false);
                Context.ApplicationInstance.CompleteRequest();

            }
        }
Exemplo n.º 11
0
 public IQueryable<Brick> GetBricks()
 {
     var _db = new ZVerseBrickProject.Models.ProductContext();
     IQueryable<Brick> query = _db.Bricks;
     return query;
 }
Exemplo n.º 12
0
 /* Obtain all the school categories of the products */
 public IQueryable<Category> GetCategories()
 {
     var _db = new ZVerseBrickProject.Models.ProductContext();
     IQueryable<Category> query = _db.Categories;
     return query;
 }
Exemplo n.º 13
0
 /* Responsible for the hyperlink to the product or brick detail page */
 protected void producturlClick(object sender, CommandEventArgs e)
 {
     int productid = Convert.ToInt32(e.CommandArgument.ToString());
     Debug.WriteLine("shopping cart: " + productid);
     if (productid > 15)
     {
         ProductContext _db = new ProductContext();
         int brickid = (from b in _db.Bricks where b.pid == productid select b.BrickID).FirstOrDefault();
         Response.Redirect("TestDisplay.aspx?brickID=" + brickid);
     }else
     {
         Response.Redirect("ProductDetails.aspx?productID=" + productid);
     }
     Context.ApplicationInstance.CompleteRequest();
 }
Exemplo n.º 14
0
 /* Update the shopping cart table in database when update check button is pressed */
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new ZVerseBrickProject.Models.ProductContext())
     {
         try
         {
             int CartItemCount = CartItemUpdates.Count();
             List<CartItem> myCart = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 // Iterate through all rows within shopping cart list
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.Product.ProductID == CartItemUpdates[i].ProductId)
                     {
                         if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                         {
                             RemoveItem(cartId, cartItem.ProductId);
                         }
                         else
                         {
                             UpdateItem(cartId, cartItem.ProductId, CartItemUpdates[i].PurchaseQuantity);
                         }
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemplo n.º 15
0
 /* Update the quantity of an item in the database */
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new ZVerseBrickProject.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems where c.CartId == updateCartID && c.Product.ProductID == updateProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Exemplo n.º 16
0
        /* Remove an item from the cart in the databse */
        public void RemoveItem(string removeCartID, int removeProductID)
        {
            using (var _db = new ZVerseBrickProject.Models.ProductContext())
            {
                try
                {
                    var myItem = (from c in _db.ShoppingCartItems where c.CartId == removeCartID && c.Product.ProductID == removeProductID select c).FirstOrDefault();
                    if (myItem != null)
                    {
                        // Remove Item.
                        _db.ShoppingCartItems.Remove(myItem);

                        //remove custom models
                        if (removeProductID > 15)
                        {
                            Brick thebrick;
                            Product theproduct;
                            int brickid = (from b in _db.Bricks where b.pid == removeProductID select b.BrickID).FirstOrDefault();
                            thebrick = _db.Bricks.Find(brickid);
                            theproduct = _db.Products.Find(removeProductID);

                            _db.Bricks.Remove(thebrick);
                            _db.Products.Remove(theproduct);
                        }

                        _db.SaveChanges();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
                }
            }
        }
Exemplo n.º 17
0
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    if (FileUploadControl.PostedFile.ContentType == "application/javascript")
                    {
                        string fileName = Path.GetFileName(FileUploadControl.FileName);
                        FileUploadControl.SaveAs(Server.MapPath("~/js/") + fileName);
                        StatusLabel.Text = "Upload status: File uploaded!";

                        var _db = new ZVerseBrickProject.Models.ProductContext();
                        AddProducts products = new AddProducts();
                        AddBricks bricks = new AddBricks();
                        int currentID = products.AddProduct("New Product", "Newly Released Product!", "5", "2", "newUpload.jpg", "test");
                        bricks.AddBrick(currentID, "New Model", "admin uploaded model", "test", "5", "newUpload.jpg", fileName, false, "Show", true, "", "", "");
                    }
                    else
                        StatusLabel.Text = "Upload status: Only Javascript files are accepted!";
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }

            }
        }