public ActionResult ProductSheetPartial(int?csid = 1) { var _p = db.Products.ToList(); var _pc = db.ProductColors.ToList(); var _Msort = db.CategoryMiddles.ToList(); var _Ssort = db.CategorySmalls.ToList(); var _supply = db.Suppliers.ToList(); List <ProductMaintainViewModel> _ListPMVM = new List <ProductMaintainViewModel>(); foreach (var _beta in _p.Where(W => W.CategorySID == csid)) { ProductMaintainViewModel _PMVM = new ProductMaintainViewModel(); //商品編號 _PMVM.ProductID = _beta.ProductID; //商品圖示 parameter ProductID=pid,ProductColorID=cid GetImageByte(int pid, int cid) //var _dotphoto = db.ProductColors.Where(W => W.ProductID == _beta.ProductID).FirstOrDefault(); //_PMVM.PhotoID = _dotphoto.PhotoID; //var a = _pc.Where(x => x.ProductID == _beta.ProductID).FirstOrDefault(); //_PMVM.PhotoID = a.PhotoID; if (db.ProductPhotoes.Any(x => x.ProductID == _beta.ProductID && ((x.PhotoID == null ? 0 : x.PhotoID) > 0))) { _PMVM.PhotoID = (int)db.ProductPhotoes.Where(x => x.ProductID == _beta.ProductID).FirstOrDefault().PhotoID; } //商品名稱 _PMVM.ProductName = _beta.ProductName; //分類名稱 var _dotSsort = _Ssort.Where(W => W.CategorySID == _beta.CategorySID).FirstOrDefault(); _PMVM.CategorySName = _dotSsort.CategorySName; var _cmid = _Msort.Where(W => W.CategoryMID == _beta.CategorySmall.CategoryMID).FirstOrDefault(); _PMVM.CategoryMName = _cmid.CategoryMName; _PMVM.CategroyMSName = _PMVM.CategoryMName + "-" + _PMVM.CategorySName; //供應商 var _supplyid = _supply.Where(W => W.SupplierID == _beta.Supplier.SupplierID).FirstOrDefault(); _PMVM.SupplierName = _supplyid.SupplierName; //上架日期 _PMVM.ProductInDate = _beta.ProductInDate; //下架日期 _PMVM.ProductOutDate = _beta.ProductOutDate; //單價 _PMVM.UnitPrice = _beta.UnitPrice; _ListPMVM.Add(_PMVM); } return(PartialView(_ListPMVM.ToList())); }
public ActionResult Edit(ProductMaintainViewModel _form) { Product _P = new Product(); _P.ProductID = _form.ProductID; _P.ProductName = _form.ProductName; _P.Desctiption = _form.Desctiption; _P.UnitPrice = _form.UnitPrice; _P.CategorySID = _form.CategorySID; _P.SupplierID = (int)_form.SupplierID; _P.ProductInDate = _form.ProductInDate; _P.ProductOutDate = _form.ProductOutDate; db.Entry(_P).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(int id = 1) { ViewBag.CateSMName = new SelectList(db.VW_EW_CategorySM, "CategorySID", "CategoryName"); ViewBag.Supplier = new SelectList(db.Suppliers, "SupplierID", "SupplierName"); List <ProductMaintainViewModel> _ListPMVM = new List <ProductMaintainViewModel>(); ProductMaintainViewModel _PMVM = new ProductMaintainViewModel(); var _pdt = db.Products.Find(id); _PMVM.ProductID = _pdt.ProductID; _PMVM.ProductName = _pdt.ProductName; _PMVM.Desctiption = _pdt.Desctiption; _PMVM.UnitPrice = _pdt.UnitPrice; _PMVM.CategorySID = _pdt.CategorySID; _PMVM.SupplierID = (int)_pdt.SupplierID; _PMVM.ProductInDate = _pdt.ProductInDate; _PMVM.ProductOutDate = _pdt.ProductOutDate; return(View(_PMVM)); }