public static string[] getEachProductImages(KumaModel db) { var currentCart = GetCurrentCart(); int count = currentCart.Count; var images = new string[count]; for (var i = 0; i < currentCart.Count; i++) { var cartItem = currentCart.cartItems[i]; //如果這個物品本身就有圖片,就拿自己的第一張圖 if (db.Images.Any(x => x.PDID == cartItem.PDID)) { images[i] = db.Images.First(x => x.PDID == cartItem.PDID).ImgName; } //如果這個物品本身沒有圖片 else { var sameProductImage = //找出此物品所屬的產品所有關聯的圖片 from p in db.Products join pd in db.ProductDetails on p.ProductID equals pd.ProductID join img in db.Images on pd.PDID equals img.PDID where p.ProductID == cartItem.ProductID && pd.ColorID == cartItem.ColorID select new { ImgName = img.ImgName }; images[i] = sameProductImage.First().ImgName; } } return(images); }
public KumaRepository(KumaModel context) { if (context == null) { throw new ArgumentNullException(); } _context = context; }
public ProductViewModelService(KumaModel db, int pid) { DB = db; PID = pid; PVM = new ProductViewModel() { CategoryName = GetCategoryName(), Product = GetProduct(), ProductDetailViewModels = GetProductDetailViewModels(), Images = GetImages(), DesSubTitles = GetDeSubtitles(), DesDetails = GetDetails() }; }
public static int[] getEachProductStocks() //取得購物車中物品每個庫存,給Jquery防呆用 { KumaModel db = new KumaModel(); var currentCart = GetCurrentCart(); int count = currentCart.Count; var stocks = new int[count]; for (var i = 0; i < currentCart.Count; i++) { foreach (var item in db.ProductDetails) { if (item.PDID == currentCart.cartItems[i].PDID) { stocks[i] = item.Stock; break; } } } return(stocks); }
public AccountController() { db = new KumaModel(); }
public HomeController() { db = new KumaModel(); }
public SearchController() { db = new KumaModel(); }
public CartController() { db = new KumaModel(); currentCart = CartService.GetCurrentCart(); }
public ProductsService(KumaModel db) { this.db = db; }