Пример #1
0
 public IActionResult CreateProduct(ProductModel product)
 {
     if (ModelState.IsValid)
     {
         decimal k = _productRepo.CreateProduct(product);
         if (k != 0)
         {
             return(RedirectToAction(nameof(GetAll)));
         }
     }
     return(View(product));
 }
Пример #2
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!";
            }
        }