public ActionResult Create([Bind(Include = "Id,Poid,Introduction,Details")] Products products, HttpPostedFileBase[] files)
        {
            if (ModelState.IsValid)
            {
                products.Poid =Convert.ToInt32( TempData["OwnerId"]);
                db.Productses.Add(products);
                db.SaveChanges();

                if (files != null)
                {
                    UploadImages ui=new UploadImages();
                    foreach (HttpPostedFileBase file in files)
                    {
                        string filename = System.IO.Path.GetFileName(file.FileName);
                        file.SaveAs(Server.MapPath("~/Images/" + filename));
                        string filepathtosave = "Images/" + filename;
                        //ui.ProductId = 1;
                        ui.ImageName = filename;
                        ui.ProductId = products.Id;
                        db.UploadImageses.Add(ui);
                        db.SaveChanges();
                    }

                  //  db.SaveChanges();
                    ViewBag.Message = "File Uploaded successfully.";
                }
                return RedirectToAction("Index");
            }

            ViewBag.Poid = new SelectList(db.ProductOwners, "Id", "CompanyName", products.Poid);
            return View(products);
        }
 public ActionResult Edit([Bind(Include = "Id,Poid,Introduction,Details")] Products products,UploadImages UploadImageses)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.Poid = new SelectList(db.ProductOwners, "Id", "CompanyName", products.Poid);
     return View(products);
 }
 public IHttpActionResult PostProducts(ProductsList productsList)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     Products productes = new Products();
     //productes. = productsList.Poid;
     productes.MProductId = productsList.MProductId;
     productes.Introduction = productsList.Introduction;
     productes.Details = productsList.Details;
     productes.VideoLink = productsList.VideoLink;
     db.Productses.Add(productes);
     db.SaveChanges();
     var images = productsList.UploadImagesName.Split(',');
     UploadImages ui = new UploadImages();
     for (int i = 0; i < images.Length; i++)
     {
         if (images[i] == "" || images[i] == null)
         {
         }else
         {
             ui.ProductId = productes.Id;
             ui.ImageName = images[i];
             db.UploadImageses.Add(ui);
             db.SaveChanges();
         }
     }
     return  Ok(productes);
 }