Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(long id)
        {
            ProductImgs productImgs = db.ProductImgs.Find(id);

            db.ProductImgs.Remove(productImgs);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "ProductImgId,ProductId,imgLink")] ProductImgs productImgs)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productImgs).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productImgs));
 }
Ejemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ProductImgId,ProductId,imgLink")] ProductImgs productImgs)
        {
            if (ModelState.IsValid)
            {
                db.ProductImgs.Add(productImgs);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productImgs));
        }
Ejemplo n.º 4
0
        private void PutImgs(Product product)
        {
            XbooxLibraryDBContext           context = new XbooxLibraryDBContext();
            GeneralRepository <ProductImgs> ImgRepo = new GeneralRepository <ProductImgs>(context);

            //   var imgList = getImg().Split(',').Where(x=>x!="").ToList();


            //用list傳的
            foreach (var i in GetImg())
            {
                ProductImgs productImgs = new ProductImgs()
                {
                    // ProductImgId = 0,
                    imgLink   = i,
                    ProductId = product.ProductId,
                };
                ImgRepo.Create(productImgs);
                // context.ProductImgs.Add(productImgs);
            }



            //   用string 傳的
            //     foreach (var i in imgList)
            //    {
            //        productImgs = new ProductImgs()
            ////        {
            // ProductImgId = 0,
            //             imgLink = i,
            //             ProductId = product.ProductId,
            //          };
            //         context.ProductImgs.Add(productImgs);
            //productImgs.Add(new ProductImgs() { imgLink = i.ToString(), ProductId = product.ProductId });
            //    }


            // context.SaveChanges();

            //  var PiList = new List<ProductImgs>();
            // var img = productImgs
            ///    var productImgs = productImgs.Where(x => x.ProductId == product.ProductId);
            //    freach (var i in productImgs)
            //   {
            //   product.ProductImgId = i.ProductImgId + ",";
            //product.ProductImgId = Convert.ToInt64(product.ProductImgId) + ",";
            //   }

            //    imgString = null;
            ImgstringList = null;
            ImgRepo.SaveContext();
        }
Ejemplo n.º 5
0
 public IActionResult CreateProduct(Products newProduct, ProductImgs newImg, Inventory newInventory)
 {
     if (ModelState.IsValid)
     {
         _context.Products.Add(newProduct);
         _context.SaveChanges();
         TempData["product_id"] = newProduct.id;
         TempData["image"]      = newImg.img_url;
         TempData["inventory"]  = newInventory.quantity_new;
         return(RedirectToAction("CreateImage"));
     }
     return(View("Index"));
 }
Ejemplo n.º 6
0
        // GET: ProductImgs/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductImgs productImgs = db.ProductImgs.Find(id);

            if (productImgs == null)
            {
                return(HttpNotFound());
            }
            return(View(productImgs));
        }
Ejemplo n.º 7
0
 public IActionResult CreateImage()
 {
     if (ModelState.IsValid)
     {
         ProductImgs image = new ProductImgs()
         {
             img_url    = (string)TempData["image"],
             ProductsId = (int)TempData["product_id"]
         };
         _context.ProductImgs.Add(image);
         _context.SaveChanges();
         TempData["product_id"] = TempData["product_id"];
         TempData["inventory"]  = TempData["inventory"];
         return(RedirectToAction("CreateInventory"));
     }
     return(View("Index"));
 }
Ejemplo n.º 8
0
 public IActionResult AddImage(ProductImgs newImg)
 {
     if (ModelState.IsValid)
     {
         _context.ProductImgs.Add(newImg);
         _context.SaveChanges();
         List <Products> product = _context.Products.Where(x => x.id == newImg.ProductsId)
                                   .Include(y => y.product_category).ThenInclude(z => z.Category)
                                   .Include(y => y.product_img)
                                   .Include(y => y.Prices)
                                   .Include(y => y.Inventory)
                                   .ToList();
         ViewBag.products       = product;
         ViewBag.images         = _context.Products.Where(x => x.id == newImg.ProductsId).Include(y => y.product_img).ToList();
         ViewBag.prices         = _context.Products.Where(x => x.id == newImg.ProductsId).Include(y => y.Prices).ToList();
         ViewBag.inventory      = _context.Products.Where(x => x.id == newImg.ProductsId).Include(y => y.Inventory).ToList();
         ViewBag.categories     = _context.Products.Where(x => x.id == newImg.ProductsId).Include(y => y.product_category).ThenInclude(z => z.Category).ToList();
         ViewBag.all_categories = _context.Categories.ToList();
         return(Redirect("products/" + newImg.ProductsId));
     }
     return(View("Index"));
 }
Ejemplo n.º 9
0
        private void PutImgs(Product product)
        {
            var productImgs = new ProductImgs();
            XbooxLibraryDBContext           context = new XbooxLibraryDBContext();
            GeneralRepository <ProductImgs> Imgrepo = new GeneralRepository <ProductImgs>(context);

            //   var imgList = getImg().Split(',').Where(x=>x!="").ToList();


            //用list傳的
            foreach (var i in GetImg())
            {
                productImgs = new ProductImgs()
                {
                    // ProductImgId = 0,
                    imgLink   = i,
                    ProductId = product.ProductId,
                };
                Imgrepo.Create(productImgs);
            }

            ImgstringList = null;
            Imgrepo.SaveContext();
        }