public async Task <IActionResult> List(DataSourceRequest command)
        {
            var tags        = (await _productTagService.GetAllProductTags());
            var productTags = new List <ProductTagModel>();

            foreach (var item in tags)
            {
                var ptag = new ProductTagModel();
                ptag.Id           = item.Id;
                ptag.Name         = item.Name;
                ptag.ProductCount = await _productTagService.GetProductCount(item.Id, "");

                productTags.Add(ptag);
            }

            var gridModel = new DataSourceResult
            {
                Data  = productTags.OrderByDescending(x => x.ProductCount).PagedForCommand(command),
                Total = tags.Count()
            };

            return(Json(gridModel));
        }
        public async Task <IActionResult> Edit(ProductTagModel model)
        {
            var productTag = await _productTagService.GetProductTagById(model.Id);

            if (productTag == null)
            {
                //No product tag found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productTag.Name    = model.Name;
                productTag.Locales = model.Locales.ToLocalizedProperty();
                productTag.SeName  = SeoExtensions.GetSeName(productTag.Name, _seoSettings);
                await _productTagService.UpdateProductTag(productTag);

                ViewBag.RefreshPage = true;
                return(View(model));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult ProductTagsAll()
        {
            var store = Services.StoreContext.CurrentStore;
            var model = new PopularProductTagsModel();

            model.Tags = _productTagService
                         .GetAllProductTags()
                         .Where(x => _productTagService.GetProductCount(x.Id, store.Id) > 0)
                         .OrderBy(x => x.GetLocalized(y => y.Name))
                         .Select(x =>
            {
                var ptModel = new ProductTagModel
                {
                    Id           = x.Id,
                    Name         = x.GetLocalized(y => y.Name),
                    SeName       = x.GetSeName(),
                    ProductCount = _productTagService.GetProductCount(x.Id, store.Id)
                };
                return(ptModel);
            })
                         .ToList();

            return(View(model));
        }
예제 #4
0
        public virtual PopularProductTagsModel PrepareProductTagsAllModel()
        {
            var model = new PopularProductTagsModel();

            model.Tags = _productTagService
                         .GetAllProductTags()
                         //filter by current store
                         .Where(x => _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id) > 0)
                         //sort by name
                         .OrderBy(x => x.GetLocalized(y => y.Name))
                         .Select(x =>
            {
                var ptModel = new ProductTagModel
                {
                    Id           = x.Id,
                    Name         = x.GetLocalized(y => y.Name),
                    SeName       = x.GetSeName(),
                    ProductCount = _productTagService.GetProductCount(x.Id, _storeContext.CurrentStore.Id)
                };
                return(ptModel);
            })
                         .ToList();
            return(model);
        }
예제 #5
0
        public async Task <IActionResult> Edit(ProductTagModel model)
        {
            var productTag = await _productTagService.GetProductTagById(model.Id);

            if (productTag == null)
            {
                //No product tag found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productTag.Name    = model.Name;
                productTag.Locales = model.Locales.ToTranslationProperty();
                productTag.SeName  = SeoExtensions.GetSeName(productTag.Name, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion);
                await _productTagService.UpdateProductTag(productTag);

                Success(_translationService.GetResource("Admin.Catalog.ProductTags.Updated"));

                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            //If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #6
0
        public ActionResult EditProductTag(string btnId, string formId, ProductTagModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductTags))
                return AccessDeniedView();

            var productTag = _productTagService.GetProductTagById(model.Id);
            if (productTag == null)
                //No product tag found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                productTag.Name = model.Name;
                _productTagService.UpdateProductTag(productTag);
                //locales
                UpdateLocales(productTag, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #7
0
        //edit
        public ActionResult EditProductTag(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductTags))
                return AccessDeniedView();

            var productTag = _productTagService.GetProductTagById(id);
            if (productTag == null)
                //No product tag found with the specified id
                return RedirectToAction("List");

            var model = new ProductTagModel()
            {
                Id = productTag.Id,
                Name = productTag.Name,
                ProductCount = _productTagService.GetProductCount(productTag.Id, 0)
            };
            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = productTag.GetLocalized(x => x.Name, languageId, false, false);
            });

            return View(model);
        }
예제 #8
0
 private void UpdateLocales(ProductTag productTag, ProductTagModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(productTag,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
예제 #9
0
 public static ProductTag ToEntity(this ProductTagModel model, ProductTag destination)
 {
     return(model.MapTo(destination));
 }
예제 #10
0
 public static ProductTag ToEntity(this ProductTagModel model)
 {
     return(model.MapTo <ProductTagModel, ProductTag>());
 }