예제 #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Product product = new Product();
                product.ProdName        = txtName.Text.ToString();
                product.ProdPrice       = Convert.ToDecimal(txtPrice.Text);
                product.ProdDescription = txtPDescription.Text.ToString();
                product.CategoryId      = Convert.ToInt32(ddlCategory.SelectedItem.Value);
                product.ProductTypeId   = Convert.ToInt32(ddlProdType.SelectedItem.Value);
                if (imgUploader.HasFile)
                {
                    int            length  = imgUploader.PostedFile.ContentLength;
                    byte[]         imgbyte = new byte[length];
                    HttpPostedFile img     = imgUploader.PostedFile;
                    //set the binary data
                    img.InputStream.Read(imgbyte, 0, length);
                    string filename = Path.GetFileName(imgUploader.PostedFile.FileName);

                    //be.Eimage=txtimage.
                    product.PhotoName = filename;
                    product.Photo     = imgbyte;
                }
                clsProduct _product = new clsProduct();
                _product.AddProduct(product);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
 public ActionResult AddProduct(MainProduct objMP)
 {
     Prod = new clsProduct();
     try
     {
         if (ModelState.IsValid)
         {
             if (Prod.AddProduct(objMP.Pid, objMP.ProductName, objMP.Price, objMP.Model, objMP.Color, objMP.Cid))
             {
                 return(RedirectToAction("ProductList", "Product"));
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     return(View());
 }