Beispiel #1
0
        public ActionResult Picker(EntityPickerModel model, FormCollection form)
        {
            try
            {
                var languageId = model.LanguageId == 0 ? Services.WorkContext.WorkingLanguage.Id : model.LanguageId;
                var disableIf  = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
                var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();
                var selected   = model.Selected.SplitSafe(",");
                var returnSku  = model.ReturnField.IsCaseInsensitiveEqual("sku");

                using (var scope = new DbContextScope(Services.DbContext, autoDetectChanges: false, proxyCreation: true, validateOnSave: false, forceNoTracking: true))
                {
                    if (model.EntityType.IsCaseInsensitiveEqual("product"))
                    {
                        model.SearchTerm = model.SearchTerm.TrimSafe();

                        var hasPermission             = Services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog);
                        var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct");
                        var disableIfGroupedProduct   = disableIf.Contains("groupedproduct");
                        var labelTextGrouped          = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Text;
                        var labelTextBundled          = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Text;
                        var sku = T("Products.Sku").Text;

                        var fields = new List <string> {
                            "name"
                        };
                        if (_searchSettings.SearchFields.Contains("sku"))
                        {
                            fields.Add("sku");
                        }
                        if (_searchSettings.SearchFields.Contains("shortdescription"))
                        {
                            fields.Add("shortdescription");
                        }

                        var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchTerm)
                                          .HasStoreId(model.StoreId);

                        if (!hasPermission)
                        {
                            searchQuery = searchQuery.VisibleOnly(Services.WorkContext.CurrentCustomer);
                        }

                        if (model.ProductTypeId > 0)
                        {
                            searchQuery = searchQuery.IsProductType((ProductType)model.ProductTypeId);
                        }

                        if (model.ManufacturerId != 0)
                        {
                            searchQuery = searchQuery.WithManufacturerIds(null, model.ManufacturerId);
                        }

                        if (model.CategoryId != 0)
                        {
                            var node = _categoryService.GetCategoryTree(model.CategoryId, true);
                            if (node != null)
                            {
                                searchQuery = searchQuery.WithCategoryIds(null, node.Flatten(true).Select(x => x.Id).ToArray());
                            }
                        }

                        var skip  = model.PageIndex * model.PageSize;
                        var query = _catalogSearchService.PrepareQuery(searchQuery);

                        var products = query
                                       .Select(x => new
                        {
                            x.Id,
                            x.Sku,
                            x.Name,
                            x.Published,
                            x.ProductTypeId,
                            x.MainPictureId
                        })
                                       .OrderBy(x => x.Name)
                                       .Skip(() => skip)
                                       .Take(() => model.PageSize)
                                       .ToList();

                        var allPictureIds   = products.Select(x => x.MainPictureId.GetValueOrDefault());
                        var allPictureInfos = _pictureService.GetPictureInfos(allPictureIds);

                        model.SearchResult = products
                                             .Select(x =>
                        {
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                Title        = x.Name,
                                Summary      = x.Sku,
                                SummaryTitle = "{0}: {1}".FormatInvariant(sku, x.Sku.NaIfEmpty()),
                                Published    = hasPermission ? x.Published : (bool?)null,
                                ReturnValue  = returnSku ? x.Sku : x.Id.ToString()
                            };

                            item.Selected = selected.Contains(item.ReturnValue);

                            if (disableIfNotSimpleProduct)
                            {
                                item.Disable = x.ProductTypeId != (int)ProductType.SimpleProduct;
                            }
                            else if (disableIfGroupedProduct)
                            {
                                item.Disable = x.ProductTypeId == (int)ProductType.GroupedProduct;
                            }

                            if (!item.Disable && disableIds.Contains(x.Id))
                            {
                                item.Disable = true;
                            }

                            if (x.ProductTypeId == (int)ProductType.GroupedProduct)
                            {
                                item.LabelText      = labelTextGrouped;
                                item.LabelClassName = "badge-success";
                            }
                            else if (x.ProductTypeId == (int)ProductType.BundledProduct)
                            {
                                item.LabelText      = labelTextBundled;
                                item.LabelClassName = "badge-info";
                            }

                            var pictureInfo  = allPictureInfos.Get(x.MainPictureId.GetValueOrDefault());
                            var fallbackType = _catalogSettings.HideProductDefaultPictures ? FallbackPictureType.NoFallback : FallbackPictureType.Entity;

                            item.ImageUrl = _pictureService.GetUrl(
                                allPictureInfos.Get(x.MainPictureId.GetValueOrDefault()),
                                _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage,
                                fallbackType);

                            return(item);
                        })
                                             .ToList();
                    }
                    else if (model.EntityType.IsCaseInsensitiveEqual("category"))
                    {
                        var categories      = _categoryService.GetAllCategories(model.SearchTerm, showHidden: true);
                        var allPictureIds   = categories.Select(x => x.PictureId.GetValueOrDefault());
                        var allPictureInfos = _pictureService.GetPictureInfos(allPictureIds);

                        model.SearchResult = categories
                                             .Select(x =>
                        {
                            var path = ((ICategoryNode)x).GetCategoryPath(_categoryService, languageId, "({0})");
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                Title        = x.Name,
                                Summary      = path,
                                SummaryTitle = path,
                                Published    = x.Published,
                                ReturnValue  = x.Id.ToString(),
                                Selected     = selected.Contains(x.Id.ToString()),
                                Disable      = disableIds.Contains(x.Id)
                            };

                            if (x.Alias.HasValue())
                            {
                                item.LabelText      = x.Alias;
                                item.LabelClassName = "badge-secondary";
                            }

                            var pictureInfo  = allPictureInfos.Get(x.PictureId.GetValueOrDefault());
                            var fallbackType = _catalogSettings.HideProductDefaultPictures ? FallbackPictureType.NoFallback : FallbackPictureType.Entity;

                            item.ImageUrl = _pictureService.GetUrl(
                                allPictureInfos.Get(x.PictureId.GetValueOrDefault()),
                                _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage,
                                fallbackType);

                            return(item);
                        })
                                             .ToList();
                    }
                    else if (model.EntityType.IsCaseInsensitiveEqual("manufacturer"))
                    {
                        var manufacturers   = _manufacturerService.GetAllManufacturers(model.SearchTerm, model.PageIndex, model.PageSize, showHidden: true);
                        var allPictureIds   = manufacturers.Select(x => x.PictureId.GetValueOrDefault());
                        var allPictureInfos = _pictureService.GetPictureInfos(allPictureIds);

                        model.SearchResult = manufacturers
                                             .Select(x =>
                        {
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id          = x.Id,
                                Title       = x.Name,
                                Published   = x.Published,
                                ReturnValue = x.Id.ToString(),
                                Selected    = selected.Contains(x.Id.ToString()),
                                Disable     = disableIds.Contains(x.Id)
                            };

                            var pictureInfo  = allPictureInfos.Get(x.PictureId.GetValueOrDefault());
                            var fallbackType = _catalogSettings.HideProductDefaultPictures ? FallbackPictureType.NoFallback : FallbackPictureType.Entity;

                            item.ImageUrl = _pictureService.GetUrl(
                                allPictureInfos.Get(x.PictureId.GetValueOrDefault()),
                                _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage,
                                fallbackType);

                            return(item);
                        })
                                             .ToList();
                    }
                    else if (model.EntityType.IsCaseInsensitiveEqual("customer"))
                    {
                        var registeredRoleId         = _customerService.GetCustomerRoleBySystemName("Registered").Id;
                        var searchTermName           = string.Empty;
                        var searchTermEmail          = string.Empty;
                        var searchTermCustomerNumber = string.Empty;

                        if (model.CustomerSearchType.IsCaseInsensitiveEqual("Name"))
                        {
                            searchTermName = model.SearchTerm;
                        }
                        else if (model.CustomerSearchType.IsCaseInsensitiveEqual("Email"))
                        {
                            searchTermEmail = model.SearchTerm;
                        }
                        else if (model.CustomerSearchType.IsCaseInsensitiveEqual("CustomerNumber"))
                        {
                            searchTermCustomerNumber = model.SearchTerm;
                        }

                        var q = new CustomerSearchQuery
                        {
                            SearchTerm      = searchTermName,
                            Email           = searchTermEmail,
                            CustomerNumber  = searchTermCustomerNumber,
                            CustomerRoleIds = new int[] { registeredRoleId },
                            PageIndex       = model.PageIndex,
                            PageSize        = model.PageSize
                        };

                        var customers = _customerService.SearchCustomers(q);

                        model.SearchResult = customers
                                             .Select(x =>
                        {
                            var fullName = x.GetFullName();

                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                ReturnValue  = x.Id.ToString(),
                                Title        = x.Username.NullEmpty() ?? x.Email,
                                Summary      = fullName,
                                SummaryTitle = fullName,
                                Published    = true,
                                Selected     = selected.Contains(x.Id.ToString()),
                                Disable      = disableIds.Contains(x.Id)
                            };

                            return(item);
                        })
                                             .ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                NotifyError(ex.ToAllMessages());
            }

            return(PartialView("Picker.List", model));
        }
Beispiel #2
0
        public ActionResult EntityPicker(EntityPickerModel model, FormCollection form)
        {
            model.PageSize          = 48; // _commonSettings.EntityPickerPageSize;
            model.PublishedString   = T("Common.Published");
            model.UnpublishedString = T("Common.Unpublished");

            try
            {
                var disableIf  = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
                var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();

                using (var scope = new DbContextScope(_services.DbContext, autoDetectChanges: false, proxyCreation: true, validateOnSave: false, forceNoTracking: true))
                {
                    if (model.Entity.IsCaseInsensitiveEqual("product"))
                    {
                        #region Product

                        model.SearchTerm = model.ProductName.TrimSafe();

                        var hasPermission             = _services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog);
                        var storeLocation             = _services.WebHelper.GetStoreLocation(false);
                        var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct");
                        var disableIfGroupedProduct   = disableIf.Contains("groupedproduct");
                        var labelTextGrouped          = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Text;
                        var labelTextBundled          = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Text;
                        var sku = T("Products.Sku").Text;

                        var fields = new List <string> {
                            "name"
                        };
                        if (_searchSettings.Value.SearchFields.Contains("sku"))
                        {
                            fields.Add("sku");
                        }
                        if (_searchSettings.Value.SearchFields.Contains("shortdescription"))
                        {
                            fields.Add("shortdescription");
                        }

                        var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchTerm)
                                          .HasStoreId(model.StoreId);

                        if (!hasPermission)
                        {
                            searchQuery = searchQuery.VisibleOnly(_services.WorkContext.CurrentCustomer);
                        }

                        if (model.ProductTypeId > 0)
                        {
                            searchQuery = searchQuery.IsProductType((ProductType)model.ProductTypeId);
                        }

                        if (model.ManufacturerId != 0)
                        {
                            searchQuery = searchQuery.WithManufacturerIds(null, model.ManufacturerId);
                        }

                        if (model.CategoryId != 0)
                        {
                            searchQuery = searchQuery.WithCategoryIds(null, model.CategoryId);
                        }

                        var query = _catalogSearchService.Value.PrepareQuery(searchQuery);

                        var products = query
                                       .Select(x => new
                        {
                            x.Id,
                            x.Sku,
                            x.Name,
                            x.Published,
                            x.ProductTypeId
                        })
                                       .OrderBy(x => x.Name)
                                       .Skip(model.PageIndex * model.PageSize)
                                       .Take(model.PageSize)
                                       .ToList();

                        var productIds = products.Select(x => x.Id).ToArray();
                        var pictures   = _productService.Value.GetProductPicturesByProductIds(productIds, true);

                        model.SearchResult = products
                                             .Select(x =>
                        {
                            var item = new EntityPickerModel.SearchResultModel
                            {
                                Id           = x.Id,
                                ReturnValue  = (model.ReturnField.IsCaseInsensitiveEqual("sku") ? x.Sku : x.Id.ToString()),
                                Title        = x.Name,
                                Summary      = x.Sku,
                                SummaryTitle = "{0}: {1}".FormatInvariant(sku, x.Sku.NaIfEmpty()),
                                Published    = (hasPermission ? x.Published : (bool?)null)
                            };

                            if (disableIfNotSimpleProduct)
                            {
                                item.Disable = (x.ProductTypeId != (int)ProductType.SimpleProduct);
                            }
                            else if (disableIfGroupedProduct)
                            {
                                item.Disable = (x.ProductTypeId == (int)ProductType.GroupedProduct);
                            }

                            if (!item.Disable && disableIds.Contains(x.Id))
                            {
                                item.Disable = true;
                            }

                            if (x.ProductTypeId == (int)ProductType.GroupedProduct)
                            {
                                item.LabelText      = labelTextGrouped;
                                item.LabelClassName = "badge-success";
                            }
                            else if (x.ProductTypeId == (int)ProductType.BundledProduct)
                            {
                                item.LabelText      = labelTextBundled;
                                item.LabelClassName = "badge-info";
                            }

                            var productPicture = pictures.FirstOrDefault(y => y.Key == x.Id);
                            if (productPicture.Value != null)
                            {
                                var picture = productPicture.Value.FirstOrDefault();
                                if (picture != null)
                                {
                                    try
                                    {
                                        item.ImageUrl = _pictureService.Value.GetPictureUrl(
                                            picture.Picture,
                                            _mediaSettings.Value.ProductThumbPictureSizeOnProductDetailsPage,
                                            !_catalogSettings.HideProductDefaultPictures,
                                            storeLocation);
                                    }
                                    catch (Exception exception)
                                    {
                                        exception.Dump();
                                    }
                                }
                            }

                            return(item);
                        })
                                             .ToList();

                        #endregion
                    }
                }
            }
            catch (Exception exception)
            {
                NotifyError(exception.ToAllMessages());
            }

            return(PartialView("EntityPickerList", model));
        }
        public ActionResult EntityPicker(EntityPickerModel model, FormCollection form)
        {
            model.PageSize = 48; // _commonSettings.EntityPickerPageSize;
            model.PublishedString = T("Common.Published");
            model.UnpublishedString = T("Common.Unpublished");

            try
            {
                var disableIf = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
                var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();

                using (var scope = new DbContextScope(_services.DbContext, autoDetectChanges: false, proxyCreation: true, validateOnSave: false, forceNoTracking: true))
                {
                    if (model.Entity.IsCaseInsensitiveEqual("product"))
                    {
                        #region Product

                        model.SearchTerm = model.ProductName.TrimSafe();

                        var hasPermission = _services.Permissions.Authorize(StandardPermissionProvider.ManageCatalog);
                        var storeLocation = _services.WebHelper.GetStoreLocation(false);
                        var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct");
                        var labelTextGrouped = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Text;
                        var labelTextBundled = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Text;
                        var sku = T("Products.Sku").Text;

                        var searchContext = new ProductSearchContext
                        {
                            CategoryIds = (model.CategoryId == 0 ? null : new List<int> { model.CategoryId }),
                            ManufacturerId = model.ManufacturerId,
                            StoreId = model.StoreId,
                            Keywords = model.SearchTerm,
                            ProductType = model.ProductTypeId > 0 ? (ProductType?)model.ProductTypeId : null,
                            SearchSku = !_catalogSettings.SuppressSkuSearch,
                            ShowHidden = hasPermission
                        };

                        var query = _productService.Value.PrepareProductSearchQuery(searchContext, x => new { x.Id, x.Sku, x.Name, x.Published, x.ProductTypeId });

                        query = from x in query
                                group x by x.Id into grp
                                orderby grp.Key
                                select grp.FirstOrDefault();

                        var products = query
                            .OrderBy(x => x.Name)
                            .Skip(model.PageIndex * model.PageSize)
                            .Take(model.PageSize)
                            .ToList();

                        var productIds = products.Select(x => x.Id).ToArray();
                        var pictures = _productService.Value.GetProductPicturesByProductIds(productIds, true);

                        model.SearchResult = products
                            .Select(x =>
                            {
                                var item = new EntityPickerModel.SearchResultModel
                                {
                                    Id = x.Id,
                                    ReturnValue = (model.ReturnField.IsCaseInsensitiveEqual("sku") ? x.Sku : x.Id.ToString()),
                                    Title = x.Name,
                                    Summary = x.Sku,
                                    SummaryTitle = "{0}: {1}".FormatInvariant(sku, x.Sku.NaIfEmpty()),
                                    Published = (hasPermission ? x.Published : (bool?)null)
                                };

                                if (disableIfNotSimpleProduct)
                                {
                                    item.Disable = (x.ProductTypeId != (int)ProductType.SimpleProduct);
                                }

                                if (!item.Disable && disableIds.Contains(x.Id))
                                {
                                    item.Disable = true;
                                }

                                if (x.ProductTypeId == (int)ProductType.GroupedProduct)
                                {
                                    item.LabelText = labelTextGrouped;
                                    item.LabelClassName = "label-success";
                                }
                                else if (x.ProductTypeId == (int)ProductType.BundledProduct)
                                {
                                    item.LabelText = labelTextBundled;
                                    item.LabelClassName = "label-info";
                                }

                                var productPicture = pictures.FirstOrDefault(y => y.Key == x.Id);
                                if (productPicture.Value != null)
                                {
                                    var picture = productPicture.Value.FirstOrDefault();
                                    if (picture != null)
                                    {
                                        item.ImageUrl = _pictureService.Value.GetPictureUrl(picture.Picture, _mediaSettings.Value.ProductThumbPictureSizeOnProductDetailsPage,
                                            !_catalogSettings.HideProductDefaultPictures, storeLocation);
                                    }
                                }

                                return item;
                            })
                            .ToList();

                        #endregion
                    }
                }
            }
            catch (Exception exception)
            {
                NotifyError(exception.ToAllMessages());
            }

            return PartialView("EntityPickerList", model);
        }
        public async Task <IActionResult> PickerPost(EntityPickerModel model)
        {
            try
            {
                var form       = Request.Form;
                var disableIf  = model.DisableIf.SplitSafe(",").Select(x => x.ToLower().Trim()).ToList();
                var disableIds = model.DisableIds.SplitSafe(",").Select(x => x.ToInt()).ToList();
                var selected   = model.Selected.SplitSafe(",");
                var returnSku  = model.ReturnField.EqualsNoCase("sku");

                using var scope = new DbContextScope(Services.DbContext, autoDetectChanges: false, forceNoTracking: true);
                if (model.EntityType.EqualsNoCase("product"))
                {
                    model.SearchTerm = model.SearchTerm.TrimSafe();

                    var hasPermission = await Services.Permissions.AuthorizeAsync(Permissions.Catalog.Product.Read);

                    var disableIfNotSimpleProduct = disableIf.Contains("notsimpleproduct");
                    var disableIfGroupedProduct   = disableIf.Contains("groupedproduct");
                    var labelTextGrouped          = T("Admin.Catalog.Products.ProductType.GroupedProduct.Label").Value;
                    var labelTextBundled          = T("Admin.Catalog.Products.ProductType.BundledProduct.Label").Value;
                    var sku = T("Products.Sku");

                    var fields = new List <string> {
                        "name"
                    };
                    if (_searchSettings.SearchFields.Contains("sku"))
                    {
                        fields.Add("sku");
                    }
                    if (_searchSettings.SearchFields.Contains("shortdescription"))
                    {
                        fields.Add("shortdescription");
                    }

                    var searchQuery = new CatalogSearchQuery(fields.ToArray(), model.SearchTerm)
                                      .HasStoreId(model.StoreId);

                    if (!hasPermission)
                    {
                        searchQuery = searchQuery.VisibleOnly(Services.WorkContext.CurrentCustomer);
                    }

                    if (model.ProductTypeId > 0)
                    {
                        searchQuery = searchQuery.IsProductType((ProductType)model.ProductTypeId);
                    }

                    if (model.ManufacturerId != 0)
                    {
                        searchQuery = searchQuery.WithManufacturerIds(null, model.ManufacturerId);
                    }

                    if (model.CategoryId != 0)
                    {
                        var node = await _categoryService.GetCategoryTreeAsync(model.CategoryId, true);

                        if (node != null)
                        {
                            searchQuery = searchQuery.WithCategoryIds(null, node.Flatten(true).Select(x => x.Id).ToArray());
                        }
                    }

                    List <EntityPickerProduct> products;
                    var skip = model.PageIndex * model.PageSize;

                    if (_searchSettings.UseCatalogSearchInBackend)
                    {
                        searchQuery = searchQuery
                                      .Slice(skip, model.PageSize)
                                      .SortBy(ProductSortingEnum.NameAsc);

                        var searchResult = await _catalogSearchService.SearchAsync(searchQuery);

                        products = (await searchResult.GetHitsAsync())
                                   .Select(x => new EntityPickerProduct
                        {
                            Id            = x.Id,
                            Sku           = x.Sku,
                            Name          = x.Name,
                            Published     = x.Published,
                            ProductTypeId = x.ProductTypeId,
                            MainPictureId = x.MainPictureId
                        })
                                   .ToList();
                    }
                    else
                    {
                        var query = _catalogSearchService.PrepareQuery(searchQuery).AsNoTracking();

                        products = await query
                                   .Select(x => new EntityPickerProduct
                        {
                            Id            = x.Id,
                            Sku           = x.Sku,
                            Name          = x.Name,
                            Published     = x.Published,
                            ProductTypeId = x.ProductTypeId,
                            MainPictureId = x.MainPictureId
                        })
                                   .OrderBy(x => x.Name)
                                   .Skip(skip)
                                   .Take(model.PageSize)
                                   .ToListAsync();
                    }

                    var fileIds = products
                                  .Select(x => x.MainPictureId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

                    model.SearchResult = products
                                         .Select(x =>
                    {
                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id           = x.Id,
                            Title        = x.Name,
                            Summary      = x.Sku,
                            SummaryTitle = $"{sku}: {x.Sku.NaIfEmpty()}",
                            Published    = hasPermission ? x.Published : null,
                            ReturnValue  = returnSku ? x.Sku : x.Id.ToString()
                        };

                        item.Selected = selected.Contains(item.ReturnValue);

                        if (disableIfNotSimpleProduct)
                        {
                            item.Disable = x.ProductTypeId != (int)ProductType.SimpleProduct;
                        }
                        else if (disableIfGroupedProduct)
                        {
                            item.Disable = x.ProductTypeId == (int)ProductType.GroupedProduct;
                        }

                        if (!item.Disable && disableIds.Contains(x.Id))
                        {
                            item.Disable = true;
                        }

                        if (x.ProductTypeId == (int)ProductType.GroupedProduct)
                        {
                            item.LabelText      = labelTextGrouped;
                            item.LabelClassName = "badge-success";
                        }
                        else if (x.ProductTypeId == (int)ProductType.BundledProduct)
                        {
                            item.LabelText      = labelTextBundled;
                            item.LabelClassName = "badge-info";
                        }

                        files.TryGetValue(x.MainPictureId ?? 0, out var file);
                        item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                        return(item);
                    })
                                         .ToList();
                }
                else if (model.EntityType.EqualsNoCase("category"))
                {
                    var categoryQuery = _db.Categories
                                        .AsNoTracking()
                                        .ApplyStandardFilter(includeHidden: true)
                                        .AsQueryable();

                    if (model.SearchTerm.HasValue())
                    {
                        categoryQuery = categoryQuery.Where(c => c.Name.Contains(model.SearchTerm) || c.FullName.Contains(model.SearchTerm));
                    }

                    var categories = await categoryQuery.ToListAsync();

                    var fileIds = categories
                                  .Select(x => x.MediaFileId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

                    model.SearchResult = await categories
                                         .SelectAsync(async x =>
                    {
                        var path = await _categoryService.GetCategoryPathAsync(x, Services.WorkContext.WorkingLanguage.Id, "({0})");
                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id           = x.Id,
                            Title        = x.Name,
                            Summary      = path,
                            SummaryTitle = path,
                            Published    = x.Published,
                            ReturnValue  = x.Id.ToString(),
                            Selected     = selected.Contains(x.Id.ToString()),
                            Disable      = disableIds.Contains(x.Id)
                        };

                        if (x.Alias.HasValue())
                        {
                            item.LabelText      = x.Alias;
                            item.LabelClassName = "badge-secondary";
                        }

                        files.TryGetValue(x.MediaFileId ?? 0, out var file);
                        item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                        return(item);
                    }).AsyncToList();
                }
                else if (model.EntityType.EqualsNoCase("manufacturer"))
                {
                    var manufacturerQuery = _db.Manufacturers
                                            .AsNoTracking()
                                            .ApplyStandardFilter(includeHidden: true)
                                            .AsQueryable();

                    if (model.SearchTerm.HasValue())
                    {
                        manufacturerQuery = manufacturerQuery.Where(c => c.Name.Contains(model.SearchTerm));
                    }

                    var manufacturers = await manufacturerQuery
                                        .ApplyPaging(model.PageIndex, model.PageSize)
                                        .ToListAsync();

                    var fileIds = manufacturers
                                  .Select(x => x.MediaFileId ?? 0)
                                  .Where(x => x != 0)
                                  .Distinct()
                                  .ToArray();

                    var files = (await _mediaService.GetFilesByIdsAsync(fileIds)).ToDictionarySafe(x => x.Id);

                    model.SearchResult = manufacturers
                                         .Select(x =>
                    {
                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id          = x.Id,
                            Title       = x.Name,
                            Published   = x.Published,
                            ReturnValue = x.Id.ToString(),
                            Selected    = selected.Contains(x.Id.ToString()),
                            Disable     = disableIds.Contains(x.Id)
                        };

                        files.TryGetValue(x.MediaFileId ?? 0, out var file);
                        item.ImageUrl = _mediaService.GetUrl(file, _mediaSettings.ProductThumbPictureSizeOnProductDetailsPage, null, !_catalogSettings.HideProductDefaultPictures);

                        return(item);
                    })
                                         .ToList();
                }
                else if (model.EntityType.EqualsNoCase("customer"))
                {
                    var registeredRole = await _db.CustomerRoles
                                         .AsNoTracking()
                                         .FirstOrDefaultAsync(x => x.SystemName == SystemCustomerRoleNames.Registered);

                    var registeredRoleId = registeredRole.Id;

                    var customerQuery = _db.Customers
                                        .AsNoTracking()
                                        .AsQueryable();

                    if (model.SearchTerm.HasValue())
                    {
                        if (model.CustomerSearchType.EqualsNoCase("Name"))
                        {
                            customerQuery = customerQuery.ApplySearchTermFilter(model.SearchTerm);
                        }
                        else if (model.CustomerSearchType.EqualsNoCase("Email"))
                        {
                            customerQuery = customerQuery.ApplyIdentFilter(email: model.SearchTerm, userName: model.SearchTerm);
                        }
                        else if (model.CustomerSearchType.EqualsNoCase("CustomerNumber"))
                        {
                            customerQuery = customerQuery.ApplyIdentFilter(customerNumber: model.SearchTerm);
                        }
                    }

                    var customers = await customerQuery
                                    .ApplyRolesFilter(new[] { registeredRoleId })
                                    .ApplyPaging(model.PageIndex, model.PageSize)
                                    .ToListAsync();

                    model.SearchResult = customers
                                         .Select(x =>
                    {
                        var fullName = x.GetFullName();

                        var item = new EntityPickerModel.SearchResultModel
                        {
                            Id           = x.Id,
                            ReturnValue  = x.Id.ToString(),
                            Title        = x.Username.NullEmpty() ?? x.Email,
                            Summary      = fullName,
                            SummaryTitle = fullName,
                            Published    = true,
                            Selected     = selected.Contains(x.Id.ToString()),
                            Disable      = disableIds.Contains(x.Id)
                        };

                        return(item);
                    })
                                         .ToList();
                }
            }
            catch (Exception ex)
            {
                NotifyError(ex.ToAllMessages());
            }

            return(PartialView("Picker.List", model));
        }