public DetailCakeScreenVM(Product product) { this.Name = product.Name; this.Description = product.Description; this.Amount = product.Amount.GetValueOrDefault(); this.Thumbnail = "/Images/no_image_available.jpeg"; this.QuantityInCart = QueryDB.Instance.countQuantityOfProductInCart(product.ID); CakeStoreDBEntities db = new CakeStoreDBEntities(); //Get type cake name var queryCakeType = db.TypeCakes .Where( x => x.ID == product.IDTypeCake ) .Select( x => x.NameTypeCake ); this.CakeTypeName = queryCakeType.FirstOrDefault(); //Get price string this.Price = product.Price.Value; //Get image names var queryImageNames = db.ProductImages .Where( x => x.ID_Product == product.ID ); // Generate images path var ImageNameList = queryImageNames.ToList(); string path = Directory.GetCurrentDirectory(); for (int i = 0; i < ImageNameList.Count(); ++i) { //string realImagePath = path + "\\Images\\Products\\" + Ulties.Convertor_UNICODE_ASCII(product.Name, false) + "\\" + ImageNameList[i].ImageName; string realImagePath = path + $"\\Images\\Products\\{ImageNameList[i].ImageName}"; ImageNameList[i].ImageName = realImagePath; } if (ImageNameList.Count() > 0) { this.Thumbnail = ImageNameList[0].ImageName; } this.ImageList = new List <ProductImage>(ImageNameList); }
private QueryDB() { this.db = new CakeStoreDBEntities(); }