Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Refactoring - use repository extensions (cms service)
KrzysztofPajak4b6c24fd5740
diff --git a/src/Business/Grand.Business.Cms/Services/BlogService.cs b/src/Business/Grand.Business.Cms/Services/BlogService.csindex d9820a121..7b79e639e 100644--- a/src/Business/Grand.Business.Cms/Services/BlogService.cs+++ b/src/Business/Grand.Business.Cms/Services/BlogService.cs@@ -5,8 +5,6 @@ using Grand.Domain.Data;using Grand.Infrastructure.Extensions;using Grand.SharedKernel.Extensions;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -75,7 +73,8 @@ namespace Grand.Business.Cms.Servicesint pageIndex = 0, int pageSize = int.MaxValue, bool showHidden = false, string tag = null, string blogPostName = "", string categoryId = ""){- var query = _blogPostRepository.Table;+ var query = from p in _blogPostRepository.Table+ select p;if (!string.IsNullOrEmpty(categoryId)){@@ -242,7 +241,7 @@ namespace Grand.Business.Cms.Serviceswhere (customerId == "" || c.CustomerId == customerId) && (storeId == "" || c.StoreId == storeId)select c;- return await query.ToListAsync();+ return await query.ToListAsync2();}/// <summary>@@ -262,7 +261,7 @@ namespace Grand.Business.Cms.Servicesorderby c.CreatedOnUtcselect c;- return await query.ToListAsync();+ return await query.ToListAsync2();}/// Get blog comments by identifiers@@ -277,7 +276,7 @@ namespace Grand.Business.Cms.Servicesvar query = from bc in _blogCommentRepository.Tablewhere commentIds.Contains(bc.Id)select bc;- var comments = await query.ToListAsync();+ var comments = await query.ToListAsync2();//sort by passed identifiersvar sortedComments = new List<BlogComment>();foreach (string id in commentIds)@@ -331,7 +330,7 @@ namespace Grand.Business.Cms.Services/// <returns></returns>public virtual async Task<IList<BlogCategory>> GetBlogCategoryByPostId(string blogPostId){- return await _blogCategoryRepository.Table.Where(x => x.BlogPosts.Any(x => x.BlogPostId == blogPostId)).ToListAsync();+ return await _blogCategoryRepository.Table.Where(x => x.BlogPosts.Any(x => x.BlogPostId == blogPostId)).ToListAsync2();}/// <summary>@@ -344,7 +343,7 @@ namespace Grand.Business.Cms.Servicesif (string.IsNullOrEmpty(blogCategorySeName))throw new ArgumentNullException(nameof(blogCategorySeName));- return await _blogCategoryRepository.Table.Where(x => x.SeName == blogCategorySeName.ToLowerInvariant()).FirstOrDefaultAsync();+ return await _blogCategoryRepository.Table.Where(x => x.SeName == blogCategorySeName.ToLowerInvariant()).FirstOrDefaultAsync2();}/// <summary>@@ -361,7 +360,7 @@ namespace Grand.Business.Cms.Servicesquery = query.Where(b => b.Stores.Contains(storeId) || !b.LimitedToStores);}- return await query.OrderBy(x => x.DisplayOrder).ToListAsync();+ return await query.OrderBy(x => x.DisplayOrder).ToListAsync2();}/// <summary>@@ -489,7 +488,7 @@ namespace Grand.Business.Cms.Servicesorderby bp.DisplayOrderselect bp;- return await query.ToListAsync();+ return await query.ToListAsync2();}#endregiondiff --git a/src/Business/Grand.Business.Cms/Services/NewsService.cs b/src/Business/Grand.Business.Cms/Services/NewsService.csindex 01f4215c2..6dab6942a 100644--- a/src/Business/Grand.Business.Cms/Services/NewsService.cs+++ b/src/Business/Grand.Business.Cms/Services/NewsService.cs@@ -7,8 +7,6 @@ using Grand.Infrastructure;using Grand.Infrastructure.Extensions;using Grand.SharedKernel.Extensions;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -67,7 +65,8 @@ namespace Grand.Business.Cms.Servicespublic virtual async Task<IPagedList<NewsItem>> GetAllNews(string storeId = "",int pageIndex = 0, int pageSize = int.MaxValue, bool ignorAcl = false, bool showHidden = false, string newsTitle = ""){- var query = _newsItemRepository.Table;+ var query = from p in _newsItemRepository.Table+ select p;if (!String.IsNullOrWhiteSpace(newsTitle))query = query.Where(n => n.Title != null && n.Title.ToLower().Contains(newsTitle.ToLower()));@@ -162,7 +161,7 @@ namespace Grand.Business.Cms.Serviceswhere (customerId == "" || c.CustomerId == customerId)select c;- return await query2.ToListAsync();+ return await query2.ToListAsync2();}#endregiondiff --git a/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs b/src/Business/Grand.Business.Cms/Services/PageLayoutService.csindex 1ac5c4a6e..1e1ce3b6e 100644--- a/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs+++ b/src/Business/Grand.Business.Cms/Services/PageLayoutService.cs@@ -5,8 +5,6 @@ using Grand.Infrastructure.Caching;using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Extensions;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -61,7 +59,7 @@ namespace Grand.Business.Cms.Servicesorderby pt.DisplayOrderselect pt;- return query.ToListAsync();+ return query.ToListAsync2();});}diff --git a/src/Business/Grand.Business.Cms/Services/PageService.cs b/src/Business/Grand.Business.Cms/Services/PageService.csindex 9337302a2..6dce630c4 100644--- a/src/Business/Grand.Business.Cms/Services/PageService.cs+++ b/src/Business/Grand.Business.Cms/Services/PageService.cs@@ -9,8 +9,6 @@ using Grand.Infrastructure.Caching.Constants;using Grand.Infrastructure.Extensions;using Grand.SharedKernel.Extensions;using MediatR;-using MongoDB.Driver;-using MongoDB.Driver.Linq;using System;using System.Collections.Generic;using System.Linq;@@ -78,10 +76,12 @@ namespace Grand.Business.Cms.Servicesreturn await _cacheBase.GetAsync(key, async () =>{- var query = _pageRepository.Table;+ var query = from p in _pageRepository.Table+ select p;+query = query.Where(t => t.SystemName.ToLower() == systemName.ToLower());query = query.OrderBy(t => t.Id);- var pages = await query.ToListAsync();+ var pages = await query.ToListAsync2();if (!String.IsNullOrEmpty(storeId)){pages = pages.Where(x => _aclService.Authorize(x, storeId)).ToList();@@ -100,7 +100,8 @@ namespace Grand.Business.Cms.Servicesstring key = string.Format(CacheKey.PAGES_ALL_KEY, storeId, ignorAcl);return await _cacheBase.GetAsync(key, () =>{- var query = _pageRepository.Table;+ var query = from p in _pageRepository.Table+ select p;query = query.OrderBy(t => t.DisplayOrder).ThenBy(t => t.SystemName);@@ -124,7 +125,7 @@ namespace Grand.Business.Cms.Servicesquery = query.OrderBy(t => t.SystemName);}}- return query.ToListAsync();+ return query.ToListAsync2();});}diff --git a/src/Core/Grand.Domain/Data/RepositoryExtensions.cs b/src/Core/Grand.Domain/Data/RepositoryExtensions.csindex 441ee359c..72ea81f13 100644--- a/src/Core/Grand.Domain/Data/RepositoryExtensions.cs+++ b/src/Core/Grand.Domain/Data/RepositoryExtensions.cs@@ -27,5 +27,9 @@ namespace Grand.Domain.Data{return ((IMongoQueryable<T>)query).FirstOrDefaultAsync();}+ public static Task<T> FirstOrDefaultAsync2<T>(this IQueryable<T> query)+ {+ return ((IMongoQueryable<T>)query).FirstOrDefaultAsync();+ }}}