Exemple #1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     Product p = new Product();
     p.Name = txtName.Text;
     p.Price = ToSQL.SQLToDecimal(txtPriceNew.Text);
     p.ProductType_ID = ToSQL.SQLToIntNull(ddlProductType.SelectedValue);
     p.Manufacuturer_ID = ToSQL.SQLToIntNull(ddlManufacturer.SelectedValue);
     p.Description = CKEditorControlDescription.Text;
     p.IsActive = true;
     p.IsBestSelling = chkBestSelling.Checked;
     p.IsNew = chkNew.Checked;
     p.IsSpecial = chkSpecial.Checked;
     p.DateCreated = DateTime.Now;
     if (fulImageDefault.HasFile)
     {
         ProductImage image = new ProductImage();
         string url = CheckFileShared.UploadAndRsizeImage(fulImageDefault.PostedFile);
         if (url != "")
         {
             image.Image = url;
             image.IsDefault = true;
             p.ProductImages.Add(image);
         }
     }
     HttpFileCollection uploads = Request.Files;
     //for (int fileCount = 0; fileCount < uploads.Count; fileCount++)
     foreach (HttpPostedFile uploadedFile in FileUploadJquery.PostedFiles)
     {
         ProductImage image = new ProductImage();
         string url = CheckFileShared.UploadAndRsizeImage(uploadedFile);
         if (url != "")
         {
             image.Image = url;
             image.IsDefault = false;
             p.ProductImages.Add(image);
         }
     }
     if (productRepo.CreateProduct(p) > 0)
     {
         ProductPriceHistory productPriceHistory = new ProductPriceHistory();
         productPriceHistory.Product_ID = p.ID;
         productPriceHistory.Price = p.Price;
         productPriceHistory.DateCreated = DateTime.Now;
         new ProductPriceHistoryRepo().CreateProductPriceHistory(productPriceHistory);
         Response.Redirect("~/Admincp/Management-Products.aspx");
     }
     else
     {
         lbMessage.Text = "Please check input data! Try again!";
     }
 }
Exemple #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Product p = productRepo.GetById(ToSQL.SQLToInt(Request.QueryString["ID"]));
            if (p != null)
            {
                p.Name = ToSQL.EmptyNull(txtName.Text);
                decimal priceOld = p.Price;
                p.Price = ToSQL.SQLToDecimal(txtPrice.Text);
                p.ProductType_ID = ToSQL.SQLToIntNull(ddlProductType.SelectedValue);
                p.Manufacuturer_ID = ToSQL.SQLToIntNull(ddlManufacturer.SelectedValue);
                p.Description = CKEditorControlDescription.Text;
                p.IsActive = ToSQL.SQLToBool(chkActive.Checked);
                p.IsBestSelling = ToSQL.SQLToBool(chkBestSelling.Checked);
                p.IsNew = ToSQL.SQLToBool(chkNew.Checked);
                p.IsSpecial = ToSQL.SQLToBool(chkSpecial.Checked);
                if (fulImageDefault.HasFile)
                {
                    ProductImage image = new ProductImage();
                    string url = CheckFileShared.UploadAndRsizeImage(fulImageDefault.PostedFile);
                    if (url != "")
                    {
                        var pi = p.ProductImages.FirstOrDefault(u => u.IsDefault.Value == true); if (pi != null) pi.IsDefault = false;
                        image.Image = url;
                        image.IsDefault = true;
                        p.ProductImages.Add(image);
                    }
                }

                foreach (HttpPostedFile uploadedFile in FileUploadJquery.PostedFiles)
                {
                    ProductImage image = new ProductImage();
                    string url = CheckFileShared.UploadAndRsizeImage(uploadedFile);
                    if (url != "")
                    {
                        image.Image = url;
                        image.IsDefault = false;
                        p.ProductImages.Add(image);
                    }
                }
                if (productRepo.UpdateProduct(p) > 0)
                {
                    if (priceOld != p.Price)
                    {
                        ProductPriceHistory productPriceHistory = new ProductPriceHistory();
                        productPriceHistory.Product_ID = p.ID;
                        productPriceHistory.Price = p.Price;
                        productPriceHistory.DateCreated = DateTime.Now;
                        new ProductPriceHistoryRepo().CreateProductPriceHistory(productPriceHistory);
                    }
                    Response.Redirect("~/Admincp/Management-Products.aspx");
                }
                else
                {
                    lbMessage.Text = "Please check input data! Try again!";
                }
            }
            else
            {
                Response.Redirect("Management-Products.aspx");
            }
        }