Beispiel #1
0
        private void AppendFilterOptionsToModel(ProductsByBrand model, IQueryable <Product> query)
        {
            model.FilterOption.Price.MaxPrice = query.Max(x => x.Price);
            model.FilterOption.Price.MinPrice = query.Min(x => x.Price);

            var getCategoryName = _contentLocalizationService.GetLocalizationFunction <Category>();

            model.FilterOption.Categories = query
                                            .SelectMany(x => x.Categories).Where(x => x.Category.IsPublished)
                                            .GroupBy(x => new {
                x.Category.Id,
                x.Category.Name,
                x.Category.Slug,
                x.Category.ParentId
            })
                                            .Select(g => new FilterCategory
            {
                Id       = (int)g.Key.Id,
                Name     = getCategoryName(g.Key.Id, nameof(g.Key.Name), g.Key.Name),
                Slug     = g.Key.Slug,
                ParentId = g.Key.ParentId,
                Count    = g.Count()
            })
                                            .ToList();
        }
        public IActionResult Index()
        {
            var model = new HomeViewModel();
            var getWidgetInstanceTranslations = _contentLocalizationService.GetLocalizationFunction <WidgetInstance>();

            model.WidgetInstances = _widgetInstanceService.GetPublished()
                                    .OrderBy(x => x.DisplayOrder)
                                    .Select(x => new WidgetInstanceViewModel
            {
                Id   = x.Id,
                Name = x.Name,
                ViewComponentName = x.Widget.ViewComponentName,
                WidgetId          = x.WidgetId,
                WidgetZoneId      = x.WidgetZoneId,
                Data     = x.Data,
                HtmlData = x.HtmlData
            }).ToList();

            foreach (var item in model.WidgetInstances)
            {
                item.Name     = getWidgetInstanceTranslations(item.Id, nameof(item.Name), item.Name);
                item.HtmlData = getWidgetInstanceTranslations(item.Id, nameof(item.HtmlData), item.HtmlData);
            }

            return(View(model));
        }
        private IList <ContactAreaVm> GetContactArea()
        {
            var getContactAreaName = _contentLocalizationService.GetLocalizationFunction <ContactArea>();
            var categories         = _contactAreaRepository.Query()
                                     .Where(x => !x.IsDeleted)
                                     .Select(x => new ContactAreaVm()
            {
                Id   = x.Id,
                Name = getContactAreaName(x.Id, nameof(x.Name), x.Name)
            })
                                     .ToList();

            return(categories);
        }
        private void AppendFilterOptionsToModel(SearchResult model, IQueryable <Product> query)
        {
            model.FilterOption.Price.MaxPrice = query.Max(x => x.Price);
            model.FilterOption.Price.MinPrice = query.Min(x => x.Price);

            var getCategoryName = _contentLocalizationService.GetLocalizationFunction <Category>();

            model.FilterOption.Categories = query
                                            .SelectMany(x => x.Categories)
                                            .GroupBy(x => new
            {
                x.Category.Id,
                x.Category.Name,
                x.Category.Slug,
                x.Category.ParentId
            })
                                            .Select(g => new FilterCategory
            {
                Id       = (int)g.Key.Id,
                Name     = g.Key.Name,
                Slug     = g.Key.Slug,
                ParentId = g.Key.ParentId,
                Count    = g.Count()
            }).ToList();

            foreach (var item in model.FilterOption.Categories)
            {
                item.Name = getCategoryName(item.Id, nameof(item.Name), item.Name);
            }

            // TODO an EF Core bug, so we have to do evaluation in client
            model.FilterOption.Brands = query.Include(x => x.Brand)
                                        .Where(x => x.BrandId != null).ToList()
                                        .GroupBy(x => x.Brand)
                                        .Select(g => new FilterBrand
            {
                Id    = (int)g.Key.Id,
                Name  = g.Key.Name,
                Slug  = g.Key.Slug,
                Count = g.Count()
            }).ToList();
        }
        public async Task <IViewComponentResult> InvokeAsync(long menuId)
        {
            var menu = await _menuRepository.Query().Include(x => x.MenuItems).ThenInclude(m => m.Entity).FirstOrDefaultAsync(x => x.Id == menuId);

            if (menu == null)
            {
                throw new ArgumentException($"Cannot found menu item id {menuId}");
            }

            var menuItemVms = new List <MenuItemVm>();
            var menuItems   = menu.MenuItems.Where(x => !x.ParentId.HasValue).OrderBy(x => x.DisplayOrder);

            var menuItemEntityTypes            = menu.MenuItems.Where(x => x?.Entity?.EntityTypeId != null).Select(x => x.Entity.EntityTypeId).Distinct();
            var menuItemEntityTypeTranslations = menuItemEntityTypes.ToDictionary(k => k, v => _contentLocalizationService.GetLocalizationFunction(entityType: v));

            foreach (var item in menuItems)
            {
                var menuItemVm = Map(item, menuItemEntityTypeTranslations);
                menuItemVms.Add(menuItemVm);
            }

            return(View(this.GetViewPath(), menuItemVms));
        }