/// <summary> /// Gets all categories /// </summary> /// <param name="categoryName">Category name</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Categories</returns> public virtual IPagedList <Category> GetAllCategories(string categoryName = "", int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false) { var query = _categoryRepository.GetAll(); if (!showHidden) { query = query.Where(c => c.Published); } if (!String.IsNullOrWhiteSpace(categoryName)) { query = query.Where(c => c.Name.Contains(categoryName)); } query = query.Where(c => !c.Deleted); query = query.OrderBy(c => c.ParentCategoryId).ThenBy(c => c.DisplayOrder); if (!showHidden && (!CatalogSettings.IgnoreAcl || !CatalogSettings.IgnoreStoreLimitations)) { //if (!CatalogSettings.IgnoreAcl) //{ // //ACL (access control list) // var allowedCustomerRolesIds = _workContext.CurrentCustomer.GetCustomerRoleIds(); // query = from c in query // join acl in _aclRepository.Table // on new { c1 = c.Id, c2 = "Category" } equals new { c1 = acl.EntityId, c2 = acl.EntityName } into c_acl // from acl in c_acl.DefaultIfEmpty() // where !c.SubjectToAcl || allowedCustomerRolesIds.Contains(acl.CustomerRoleId) // select c; //} if (!CatalogSettings.IgnoreStoreLimitations) { //Store mapping var currentStoreId = _storeContext.CurrentStore.Id; query = from c in query join sm in _storeMappingRepository.GetAll() on new { c1 = c.Id, c2 = "Category" } equals new { c1 = sm.EntityId, c2 = sm.EntityName } into c_sm from sm in c_sm.DefaultIfEmpty() where !c.LimitedToStores || currentStoreId == sm.StoreId select c; } //only distinct categories (group by ID) query = from c in query group c by c.Id into cGroup orderby cGroup.Key select cGroup.FirstOrDefault(); query = query.OrderBy(c => c.ParentCategoryId).ThenBy(c => c.DisplayOrder); } var unsortedCategories = query.ToList(); //sort categories var sortedCategories = unsortedCategories.SortCategoriesForTree(); //paging return(new PagedList <Category>(sortedCategories, pageIndex, pageSize)); }
/// <summary> /// Gets all manufacturers /// </summary> /// <param name="manufacturerName">Manufacturer name</param> /// <param name="pageIndex">Page index</param> /// <param name="pageSize">Page size</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Manufacturers</returns> public virtual IPagedList <Manufacturer> GetAllManufacturers(string manufacturerName = "", int pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false) { var query = _manufacturerRepository.GetAll(); if (!showHidden) { query = query.Where(m => m.Published); } if (!String.IsNullOrWhiteSpace(manufacturerName)) { query = query.Where(m => m.Name.Contains(manufacturerName)); } query = query.Where(m => !m.Deleted); query = query.OrderBy(m => m.DisplayOrder); if (!showHidden && (!CatalogSettings.IgnoreAcl || !CatalogSettings.IgnoreStoreLimitations)) { //if (!CatalogSettings.IgnoreAcl) //{ // //ACL (access control list) // var allowedCustomerRolesIds = _workContext.CurrentCustomer.GetCustomerRoleIds(); // query = from m in query // join acl in _aclRepository.Table // on new { c1 = m.Id, c2 = "Manufacturer" } equals new { c1 = acl.EntityId, c2 = acl.EntityName } into m_acl // from acl in m_acl.DefaultIfEmpty() // where !m.SubjectToAcl || allowedCustomerRolesIds.Contains(acl.CustomerRoleId) // select m; //} if (!CatalogSettings.IgnoreStoreLimitations) { //Store mapping var currentStoreId = _storeContext.CurrentStore.Id; query = from m in query join sm in _storeMappingRepository.GetAll() on new { c1 = m.Id, c2 = "Manufacturer" } equals new { c1 = sm.EntityId, c2 = sm.EntityName } into m_sm from sm in m_sm.DefaultIfEmpty() where !m.LimitedToStores || currentStoreId == sm.StoreId select m; } //only distinct manufacturers (group by ID) query = from m in query group m by m.Id into mGroup orderby mGroup.Key select mGroup.FirstOrDefault(); query = query.OrderBy(m => m.DisplayOrder); } return(new PagedList <Manufacturer>(query, pageIndex, pageSize)); }
/// <summary> /// Gets store mapping records /// </summary> /// <typeparam name="T">Type</typeparam> /// <param name="entity">Entity</param> /// <returns>Store mapping records</returns> public virtual IList <StoreMapping> GetStoreMappings(int id, string name) { //if (entity == null) // throw new ArgumentNullException("entity"); int entityId = id; string entityName = name; var query = from sm in _storeMappingRepository.GetAll() where sm.EntityId == entityId && sm.EntityName == entityName select sm; var storeMappings = query.ToList(); return(storeMappings); }
/// <summary> /// Gets all countries /// </summary> /// <param name="languageId">Language identifier. It's used to sort countries by localized names (if specified); pass 0 to skip it</param> /// <param name="showHidden">A value indicating whether to show hidden records</param> /// <returns>Countries</returns> public virtual IList <Country> GetAllCountries(int languageId = 0, bool showHidden = false) { string key = string.Format(COUNTRIES_ALL_KEY, languageId, showHidden); return(_cacheManager.GetCache(CACHE_NAME_COUNTRY).Get(key, () => { var query = _countryRepository.GetAll(); if (!showHidden) { query = query.Where(c => c.Published); } query = query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Name); if (!showHidden && !CatalogSettings.IgnoreStoreLimitations) { //Store mapping var currentStoreId = _storeContext.CurrentStore.Id; query = from c in query join sc in _storeMappingRepository.GetAll() on new { c1 = c.Id, c2 = "Country" } equals new { c1 = sc.EntityId, c2 = sc.EntityName } into c_sc from sc in c_sc.DefaultIfEmpty() where !c.LimitedToStores || currentStoreId == sc.StoreId select c; //only distinct entities (group by ID) query = from c in query group c by c.Id into cGroup orderby cGroup.Key select cGroup.FirstOrDefault(); query = query.OrderBy(c => c.DisplayOrder).ThenBy(c => c.Name); } var countries = query.ToList(); if (languageId > 0) { //we should sort countries by localized names when they have the same display order countries = countries .OrderBy(c => c.DisplayOrder) .ThenBy(x => x.Name) .ToList(); } return countries; })); }