Пример #1
0
        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);
        }
Пример #2
0
 public KumaRepository(KumaModel context)
 {
     if (context == null)
     {
         throw new ArgumentNullException();
     }
     _context = context;
 }
Пример #3
0
 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()
     };
 }
Пример #4
0
        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);
        }
Пример #5
0
 public AccountController()
 {
     db = new KumaModel();
 }
Пример #6
0
 public HomeController()
 {
     db = new KumaModel();
 }
Пример #7
0
 public SearchController()
 {
     db = new KumaModel();
 }
Пример #8
0
 public CartController()
 {
     db          = new KumaModel();
     currentCart = CartService.GetCurrentCart();
 }
Пример #9
0
 public ProductsService(KumaModel db)
 {
     this.db = db;
 }