Ejemplo n.º 1
0
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new CategoryWidgetComponentVm()
            {
                Id         = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
            };
            var settings = JsonConvert.DeserializeObject <CategoryWidgetSettings>(widgetInstance.Data);

            if (settings != null)
            {
                var category = _categoriesRepository.Query()
                               .Include(c => c.ThumbnailImage)
                               .FirstOrDefault(c => c.Id == settings.CategoryId);
                model.Category = new CategoryThumbnail()
                {
                    Id             = category.Id,
                    Description    = category.Description,
                    Name           = category.Name,
                    SeoTitle       = category.SeoTitle,
                    ThumbnailImage = category.ThumbnailImage,
                    ThumbnailUrl   = _mediaService.GetThumbnailUrl(category.ThumbnailImage)
                };
            }

            return(View("/Modules/SimplCommerce.Module.Catalog/Views/Components/CategoryWidget.cshtml", model));
        }
Ejemplo n.º 2
0
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new CategoryWidgetComponentVm()
            {
                Id         = widgetInstance.Id,
                WidgetName = _contentLocalizationService.GetLocalizedProperty(nameof(WidgetInstance), widgetInstance.Id, nameof(widgetInstance.Name), widgetInstance.Name),
            };
            var settings = JsonConvert.DeserializeObject <CategoryWidgetSettings>(widgetInstance.Data);

            if (settings != null)
            {
                var category = _categoriesRepository.Query()
                               .Include(c => c.ThumbnailImage)
                               .FirstOrDefault(c => c.Id == settings.CategoryId);
                model.Category = new CategoryThumbnail()
                {
                    Id             = category.Id,
                    Description    = category.Description,
                    Name           = category.Name,
                    Slug           = category.Slug,
                    ThumbnailImage = category.ThumbnailImage,
                    ThumbnailUrl   = _mediaService.GetThumbnailUrl(category.ThumbnailImage)
                };
            }

            return(View(this.GetViewPath(), model));
        }
Ejemplo n.º 3
0
        public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance)
        {
            var model = new CategoryWidgetComponentVm()
            {
                Id         = widgetInstance.Id,
                WidgetName = widgetInstance.Name,
            };
            var settings = JsonConvert.DeserializeObject <CategoryWidgetSettings>(widgetInstance.Data);

            if (settings != null)
            {
                var category = _categoriesRepository.Query()
                               .FirstOrDefault(c => c.Id == settings.CategoryId);
            }

            return(View("/Modules/Cctic.Module.MainMenu/Views/Components/CategoryWidget.cshtml", model));
        }
Ejemplo n.º 4
0
        public IActionResult Categories()
        {
            var widgetInstances = _widgetInstanceRepository.Query()
                                  .Where(x => x.WidgetId == WidgetIds.CategoryWidget)
                                  .OrderBy(x => x.DisplayOrder)
                                  .Select(x => new
            {
                Id         = x.Id,
                WidgetName = x.Name,
                Setting    = JsonConvert.DeserializeObject <CategoryWidgetSettings>(x.Data)
            })
                                  .ToList();

            var categoryWidgets = new List <CategoryWidgetComponentVm>();

            foreach (var item in widgetInstances)
            {
                var category = _cateRepository.Query()
                               .Include(c => c.ThumbnailImage)
                               .FirstOrDefault(c => c.Id == item.Setting.CategoryId);

                var model = new CategoryWidgetComponentVm()
                {
                    Id         = item.Id,
                    WidgetName = item.WidgetName,
                    Category   = new CategoryThumbnail()
                    {
                        Id             = category.Id,
                        Description    = category.Description,
                        Name           = category.Name,
                        Slug           = category.Slug,
                        ThumbnailImage = category.ThumbnailImage,
                        ThumbnailUrl   = _mediaService.GetThumbnailUrl(category.ThumbnailImage)
                    }
                };
                categoryWidgets.Add(model);
            }

            return(Json(categoryWidgets.Select(x => new
            {
                Id = x.Category.Id,
                Name = x.WidgetName,
                ThumbnailImageUrl = x.Category.ThumbnailUrl
            })));
        }