protected void setRandomImg() { List <Product> listProduct = QueryDB.Instance.getOriginProductList(); int lengImgArr = listProduct.Count(); this.rng = GeneratorRng.Instance.Next(lengImgArr); Product product = listProduct[rng]; string nameImage = QueryDB.Instance.getThumbnailOf1Product(product.ID); //this.namefood = this.listFoodImg[this.rng]; //Debug.WriteLine($"{this.path}/Images/splash_places/{this.namefood}.jpg"); BitmapImage bitImg = new BitmapImage(new Uri($"{this.path}\\Images\\Products\\{nameImage}", UriKind.Absolute)); splashImg.Source = bitImg; Canvas.SetLeft(splashImg, (placeImg.ActualWidth - ConstantVariable.convertDimension(splashImg.Width)) / 2); Canvas.SetTop(splashImg, 0); //StreamReader sreader = new StreamReader($"{this.path}/info/splash_places/{this.namefood}.txt"); //nameOfFood.Text = sreader.ReadLine(); //infoOfFood.Text = tab + sreader.ReadLine(); nameOfFood.Text = $"/{product.Name}/"; infoOfFood.Text = product.Description; this.Thumbnail = product.ID; }
public dynamic getBindingCakeList(int option = 0, string keyword = null, int typeFilter = -1) { var query = db.Products .Join(db.TypeCakes, product => product.IDTypeCake, type => type.ID, (product, type) => new { ID = product.ID, NameCake = product.Name, Type = type.ID, Price = product.Price, Amount = product.Amount, CountInValidDate = product.Amount, Description = product.Description, } ).GroupJoin(db.ProductImages, entity => entity.ID, image => image.ID_Product, (entity, image) => new { Product = entity, Image = image, } ) .SelectMany( empty => empty.Image.DefaultIfEmpty(), (product, image) => new { ProductEntity = product.Product, ImageEntity = image, } ) .GroupBy( obj => obj.ProductEntity, (key, listImage) => new { Key = key, ListImages = listImage.ToList() } ) .Select( entity => new { ID = entity.Key.ID, NameCake = entity.Key.NameCake, Type = entity.Key.Type, Price = entity.Key.Price, Amount = entity.Key.Amount, CountInValidDate = entity.Key.CountInValidDate, Description = entity.Key.Description, Thumbnail = entity.ListImages.FirstOrDefault().ImageEntity.ImageName } ); switch (option) { case ConstantVariable.FILTER_ALL: // do nothing break; case ConstantVariable.SORT_BY_AZ: query = query.OrderBy(x => x.NameCake); break; case ConstantVariable.SORT_BY_ZA: query = query.OrderByDescending(x => x.NameCake); break; case ConstantVariable.SORT_BY_INC_PRICE: query = query.OrderBy(x => x.Price); break; case ConstantVariable.SORT_BY_DEC_PRICE: query = query.OrderByDescending(x => x.Price); break; case ConstantVariable.FILTER_BY_TYPE: query = query.Where(x => x.Type == typeFilter); break; case ConstantVariable.FILTER_BY_KEYWORD: keyword = ConstantVariable.Convertor_UNICODE_ASCII(keyword, true); string[] keys = keyword.ToLower().Split(new char[] { '.', '?', '!', ' ', ';', ':', ',' }, StringSplitOptions.RemoveEmptyEntries); var bindingQuery = query.Select(entity => new { ID = entity.ID, Name = entity.NameCake }).AsEnumerable() .Select(entity => new { ID = entity.ID, Name = (ConstantVariable.Convertor_UNICODE_ASCII(entity.Name, true) as string) }) .Where(res => keys.All(s => (res.Name).Contains(s))) .Join(query, key => key.ID, entity => entity.ID, (key, entity) => entity ); //foreach (var item in tempList) //{ // Debug.WriteLine($"-- {item.ID} - {item.NameCake}"); //} return(bindingQuery.ToList()); break; } return(query.ToList()); }