public ActionResult AddProduct(ProductModel product)
        {
            List<string> _errList = new List<string>();
            bool _success = false;

            if (ModelState.IsValid)
            {
                try
                {
                    new ProductRepository().Add(Mapper.Map<Product>(product));
                    _success = true;
                }
                catch (DalException e)
                {
                    _errList.Add(e.Message);
                }
                catch (Exception)
                {
                    _errList.Add("DataBase Error");
                }
            }
            else
            {
                _errList = GetModelErrors();
            }

            return Json(new
            {
                success = _success,
                error = _errList
            });
        }
示例#2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Models.ProductModel productModel = new Models.ProductModel();
            List <Product>      products     = productModel.GetAllProducts();

            if (i <= products.Count)
            {
                FillPage();
            }
            else
            {
                i             -= 4;
                temp          -= 4;
                Label1.Visible = true;
                Label1.Text    = "There are no more products!";
                FillPage();
            }
        }
 public ActionResult AddProduct()
 {
     var product = new ProductModel();
     return PartialView("AddProductView", product);
 }
 public ActionResult DeleteProductR(int id)
 {
     var product = new ProductModel(){ Id = id };
     return PartialView("DeleteProductView", product);
 }
示例#5
0
        private void FillPage()
        {
            Models.ProductModel productModel = new Models.ProductModel();
            List <Product>      products     = productModel.GetAllProducts();

            if (products != null)
            {
                if (i > products.Count)
                {
                    foreach (Product product in products)
                    {
                        Panel       productPanel = new Panel();
                        ImageButton imageButton  = new ImageButton();
                        Label       lblName      = new Label();
                        Label       lblPrice     = new Label();

                        imageButton.ImageUrl    = "~/Images/Products/" + product.Image;
                        imageButton.CssClass    = "productImage";
                        imageButton.PostBackUrl = "~/Pages/Product.aspx?id=" + product.ID;

                        lblName.Text     = product.Name;
                        lblName.CssClass = "productName";

                        lblPrice.Text     = "$ " + product.Price;
                        lblPrice.CssClass = "productPrice";

                        productPanel.Controls.Add(imageButton);
                        productPanel.Controls.Add(new Literal {
                            Text = "<br />"
                        });
                        productPanel.Controls.Add(lblName);
                        productPanel.Controls.Add(new Literal {
                            Text = "<br />"
                        });
                        productPanel.Controls.Add(lblPrice);

                        pnlProducts.Controls.Add(productPanel);
                    }
                }
                else
                {
                    foreach (Product product in products)
                    {
                        temp++;
                        if (temp - 1 < i + 4 && temp > i)
                        {
                            Panel       productPanel = new Panel();
                            ImageButton imageButton  = new ImageButton();
                            Label       lblName      = new Label();
                            Label       lblPrice     = new Label();

                            imageButton.ImageUrl    = "~/Images/Products/" + product.Image;
                            imageButton.CssClass    = "productImage";
                            imageButton.PostBackUrl = "~/Pages/Product.aspx?id=" + product.ID;

                            lblName.Text     = product.Name;
                            lblName.CssClass = "productName";

                            lblPrice.Text     = "$ " + product.Price;
                            lblPrice.CssClass = "productPrice";

                            productPanel.Controls.Add(imageButton);
                            productPanel.Controls.Add(new Literal {
                                Text = "<br />"
                            });
                            productPanel.Controls.Add(lblName);
                            productPanel.Controls.Add(new Literal {
                                Text = "<br />"
                            });
                            productPanel.Controls.Add(lblPrice);

                            pnlProducts.Controls.Add(productPanel);
                        }
                    }
                    i += 4;
                }
            }
            else
            {
                pnlProducts.Controls.Add(new Literal {
                    Text = "No products Found!"
                });
            }
        }