コード例 #1
0
        // AJAX
        public ActionResult AllManufacturers(string label, int selectedId)
        {
            var manufacturers = _manufacturerService.GetAllManufacturers(true);

            if (label.HasValue())
            {
                manufacturers.Insert(0, new Manufacturer {
                    Name = label, Id = 0
                });
            }

            var list = from m in manufacturers
                       select new
            {
                id       = m.Id.ToString(),
                text     = m.GetLocalized(x => x.Name).Value,
                selected = m.Id == selectedId
            };

            var mainList = list.ToList();

            var mruList = new TrimmedBuffer <string>(
                _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.MostRecentlyUsedManufacturers),
                _catalogSettings.MostRecentlyUsedManufacturersMaxSize)
                          .Reverse()
                          .Select(x =>
            {
                var item = manufacturers.FirstOrDefault(m => m.Id.ToString() == x);
                if (item != null)
                {
                    return(new
                    {
                        id = x,
                        text = item.GetLocalized(y => y.Name).Value,
                        selected = false
                    });
                }

                return(null);
            })
                          .Where(x => x != null)
                          .ToList();

            object data = mainList;

            if (mruList.Count > 0)
            {
                data = new List <object>
                {
                    new Dictionary <string, object> {
                        ["text"] = T("Common.Mru").Text, ["children"] = mruList
                    },
                    new Dictionary <string, object> {
                        ["text"] = T("Admin.Catalog.Manufacturers").Text, ["children"] = mainList, ["main"] = true
                    }
                };
            }

            return(new JsonResult {
                Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #2
0
        // Ajax
        public ActionResult AllCategories(string label, int selectedId)
        {
            var categoryTree = _categoryService.GetCategoryTree(includeHidden: true);
            var categories   = categoryTree.Flatten(false);

            if (label.HasValue())
            {
                categories = (new[] { new Category {
                                          Name = label, Id = 0
                                      } }).Concat(categories);
            }

            var query =
                from c in categories
                select new
            {
                id       = c.Id.ToString(),
                text     = c.GetCategoryPath(_categoryService, aliasPattern: "<span class='badge badge-secondary'>{0}</span>"),
                selected = c.Id == selectedId
            };

            var mainList = query.ToList();

            var mruList = new TrimmedBuffer <string>(
                _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.MostRecentlyUsedCategories),
                _catalogSettings.MostRecentlyUsedCategoriesMaxSize)
                          .Reverse()
                          .Select(x =>
            {
                var item = categoryTree.SelectNodeById(x.ToInt());
                if (item != null)
                {
                    return(new
                    {
                        id = x,
                        text = _categoryService.GetCategoryPath(item, aliasPattern: "<span class='badge badge-secondary'>{0}</span>"),
                        selected = false
                    });
                }

                return(null);
            })
                          .Where(x => x != null)
                          .ToList();

            object data = mainList;

            if (mruList.Count > 0)
            {
                data = new List <object>
                {
                    new Dictionary <string, object> {
                        ["text"] = T("Common.Mru").Text, ["children"] = mruList
                    },
                    new Dictionary <string, object> {
                        ["text"] = T("Admin.Catalog.Categories").Text, ["children"] = mainList, ["main"] = true
                    }
                };
            }

            return(new JsonResult {
                Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #3
0
        /// <summary>
        /// Gets a list of all available manufacturers.
        /// </summary>
        /// <param name="label">Text for optional entry. If not null an entry with the specified label text and the Id 0 will be added to the list.</param>
        /// <param name="selectedId">Id of selected entity.</param>
        /// <returns>List of all manufacturers as JSON.</returns>
        public async Task <IActionResult> AllManufacturers(string label, int selectedId)
        {
            var manufacturers = await _db.Manufacturers
                                .AsNoTracking()
                                .ApplyStandardFilter(true)
                                .ToListAsync();

            if (label.HasValue())
            {
                manufacturers.Insert(0, new Manufacturer {
                    Name = label, Id = 0
                });
            }

            var list = from m in manufacturers
                       select new
            {
                id       = m.Id.ToString(),
                text     = m.GetLocalized(x => x.Name).Value,
                selected = m.Id == selectedId
            };

            var mainList = list.ToList();

            var mruList = new TrimmedBuffer <string>(
                Services.WorkContext.CurrentCustomer.GenericAttributes.MostRecentlyUsedManufacturers,
                _catalogSettings.MostRecentlyUsedManufacturersMaxSize)
                          .Reverse()
                          .Select(x =>
            {
                var item = manufacturers.FirstOrDefault(m => m.Id.ToString() == x);
                if (item != null)
                {
                    return(new
                    {
                        id = x,
                        text = item.GetLocalized(y => y.Name).Value,
                        selected = false
                    });
                }

                return(null);
            })
                          .Where(x => x != null)
                          .ToList();

            object data = mainList;

            if (mruList.Count > 0)
            {
                data = new List <object>
                {
                    new Dictionary <string, object> {
                        ["text"] = T("Common.Mru").Value, ["children"] = mruList
                    },
                    new Dictionary <string, object> {
                        ["text"] = T("Admin.Catalog.Manufacturers").Value, ["children"] = mainList, ["main"] = true
                    }
                };
            }

            return(new JsonResult(data));
        }
コード例 #4
0
        /// <summary>
        /// TODO: (mh) (core) Add documentation.
        /// </summary>
        /// <param name="label"></param>
        /// <param name="selectedIds"></param>
        /// <returns></returns>
        public async Task <IActionResult> AllCategories(string label, string selectedIds)
        {
            var categoryTree = await _categoryService.GetCategoryTreeAsync(includeHidden : true);

            var categories  = categoryTree.Flatten(false);
            var selectedArr = selectedIds.ToIntArray();

            if (label.HasValue())
            {
                categories = (new[] { new Category {
                                          Name = label, Id = 0
                                      } }).Concat(categories);
            }

            var query = categories.SelectAsync(async c => new
            {
                id       = c.Id.ToString(),
                text     = await _categoryService.GetCategoryPathAsync(c, aliasPattern: "<span class='badge badge-secondary'>{0}</span>"),
                selected = selectedArr.Contains(c.Id)
            });

            var mainList = await query.ToListAsync();

            var mruList = new TrimmedBuffer <string>(
                Services.WorkContext.CurrentCustomer.GenericAttributes.MostRecentlyUsedCategories,
                _catalogSettings.MostRecentlyUsedCategoriesMaxSize)
                          .Reverse()
                          .Select(x =>
            {
                var item = categoryTree.SelectNodeById(x.ToInt());
                if (item != null)
                {
                    return(new
                    {
                        id = x,
                        text = _categoryService.GetCategoryPath(item, aliasPattern: "<span class='badge badge-secondary'>{0}</span>"),
                        selected = false
                    });
                }

                return(null);
            })
                          .Where(x => x != null)
                          .ToList();

            object data = mainList;

            if (mruList.Count > 0)
            {
                data = new List <object>
                {
                    new Dictionary <string, object> {
                        ["text"] = T("Common.Mru").Value, ["children"] = mruList
                    },
                    new Dictionary <string, object> {
                        ["text"] = T("Admin.Catalog.Categories").Value, ["children"] = mainList, ["main"] = true
                    }
                };
            }

            return(new JsonResult(data));
        }