protected void btnSave_Click(object sender, EventArgs e)
        {
            int catId =Convert.ToInt32(ddlCategories.SelectedValue);
            if (Request.QueryString["productId"]==null)
            {
                ProductBLL pb = new ProductBLL();
                Product p = new Product();
                p.CategoryId = catId;
                p.Name = txtName.Text;
                p.Price = Convert.ToDecimal(txtPrice.Text);
                p.Stock = Convert.ToByte(txtStock.Text);
                p.Date = DateTime.Now;
                p.IsActive = true;
                p.Detail = txtDetail.Text;

                string fileName = Guid.NewGuid().ToString().Replace("-", "");
                string ext = Path.GetExtension(fl.FileName);
                fileName += ext;
                fl.SaveAs(MapPath("~/ProductImages/" + fileName));

                p.Image = fileName;

                pb.Add(p);
            }
            else
            {
                int id = Convert.ToInt32(Request.QueryString["productId"]);
                ProductBLL pb = new ProductBLL();
                Product p = pb.Get(x => x.Id == id).FirstOrDefault();

                p.Name = txtName.Text;
                p.Price = Convert.ToDecimal(txtPrice.Text);
                p.Stock = Convert.ToByte(txtStock.Text);
                p.Date = DateTime.Now;
                p.IsActive = true;
                p.Detail = txtDetail.Text;

                string fileName = Guid.NewGuid().ToString().Replace("-", "");
                string ext = Path.GetExtension(fl.FileName);
                fileName += ext;
                fl.SaveAs(MapPath("~/ProductImages/" + fileName));

                p.Image = fileName;

                pb.Update(p);
            }
            Response.Redirect("Products.aspx");
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //Product p = new Product();
            //p.Name = txtProductName.Text;
            //p.Price =Convert.ToDecimal(txtPrice.Text);
            //p.Stock =Convert.ToInt16(txtStock.Text);
            //p.CategoryId =Convert.ToInt32(ddlCategories.SelectedValue);
            //string fileName = Guid.NewGuid().ToString().Replace("-","");
            //string ext = Path.GetExtension(fl.FileName);

            //fileName += ext;

            //fl.SaveAs(MapPath("~/ProductImages/")+fileName);

            //p.IsActive = true;
            //p.Date = DateTime.Now;

            //ProductBLL pb = new ProductBLL();
            //pb.Add(p);

            //Response.Redirect("Products.aspx");
            Product p = new Product();
            p.Name = txtProductName.Text;
            p.CategoryId = Convert.ToInt32(ddlCategories.SelectedValue);
            p.Stock = Convert.ToInt16(txtStock.Text);
            p.Price = Convert.ToDecimal(txtPrice.Text);

            string fileName = Guid.NewGuid().ToString().Replace("-", "");

            string ext = Path.GetExtension(fl.FileName);

            fileName += ext;

            fl.SaveAs(MapPath("~/ProductImages/") + fileName);

            p.Image = fileName;
            p.IsActive = true;
            p.Date = DateTime.Now;

            ProductBLL pb = new ProductBLL();

            pb.Add(p);

            Response.Redirect("Products.aspx");
        }