Пример #1
0
        public IActionResult EditProduct1(tProductViewModel tProductEdit)
        {
            TProduct EditP = db.TProducts.FirstOrDefault(p => p.FProductId == tProductEdit.FProductId);

            if (EditP != null)
            {
                if (tProductEdit.imgs != null)
                {
                    foreach (var a in tProductEdit.imgs)
                    {
                        string photoName = Guid.NewGuid().ToString() + ".jpg";
                        using (var photo = new FileStream(iv_host.ContentRootPath + @"\wwwroot\img\" + photoName, FileMode.Create))
                        {
                            a.CopyTo(photo);
                        }
                        TProductPic tp = new TProductPic();
                        tp.FProductId      = tProductEdit.FProductId;
                        tp.FProductPicPath = @"/img/" + photoName;
                        db.Update(tp);
                        db.SaveChanges();
                    }
                }
                EditP.FProductName        = tProductEdit.FProductName;
                EditP.FProductPrice       = tProductEdit.FProductPrice;
                EditP.FProductQty         = tProductEdit.FProductQty;
                EditP.FProductDescription = tProductEdit.FProductDescription;
                EditP.FProductCategory    = tProductEdit.FProductCategoryId;
                EditP.FSize = tProductEdit.Size;
                db.SaveChanges();
            }
            return(RedirectToAction("ShpManagement"));
        }
Пример #2
0
        //刪除照片
        public IEnumerable <TProductPic> RemoveImg(string img)
        {
            WeNeedFriendsFINContext db  = new WeNeedFriendsFINContext();
            TProductPic             pic = db.TProductPics.FirstOrDefault(n => n.Fid == int.Parse(img));

            db.TProductPics.Remove(pic);
            db.SaveChanges();
            var Pic2 = db.TProductPics.Select(n => n);

            return(Pic2);
        }
Пример #3
0
        public IActionResult ShpAddProduct(tProductViewModel p)
        {
            db.TProducts.Add(p.product);
            db.SaveChanges();
            foreach (var a in p.imgs)
            {
                string photoName = Guid.NewGuid().ToString() + ".jpg";
                using (var photo = new FileStream(iv_host.ContentRootPath + @"\wwwroot\img\" + photoName, FileMode.Create))
                {
                    a.CopyTo(photo);
                }
                TProductPic tp = new TProductPic();
                tp.FProductPicPath = @"/img/" + photoName;
                tp.FProductId      = p.product.FProductId;
                db.TProductPics.Add(tp);
                db.SaveChanges();
            }

            return(RedirectToAction("ShpManagement"));
        }