Skip to content

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.

Refactoring - use repository extensions (common services)

KrzysztofPajaka527a9dfd568
diff --git a/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs b/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
index 9227486b0..3b817cf47 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/CountryService.cs
@@ -8,8 +8,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;
@@ -68,18 +66,21 @@ namespace Grand.Business.Common.Services.Directory
return await _cacheBase.GetAsync(key, async () =>
{
- var builder = Builders<Country>.Filter;
- var filter = builder.Empty;
+ var query = from p in _countryRepository.Table
+ select p;
if (!showHidden)
- filter &= builder.Where(c => c.Published);
+ query = query.Where(c => c.Published);
if (!showHidden && !CommonHelper.IgnoreStoreLimitations && string.IsNullOrEmpty(storeId))
{
//Store acl
- filter &= (builder.AnyIn(x => x.Stores, new List<string> { storeId }) | builder.Where(x => !x.LimitedToStores));
+ query = from p in query
+ where !p.LimitedToStores || p.Stores.Contains(storeId)
+ select p;
}
- var countries = await _countryRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder).ThenBy(x => x.Name).ToListAsync();
+
+ var countries = await query.OrderBy(x => x.DisplayOrder).ThenBy(x => x.Name).ToListAsync2();
if (!string.IsNullOrEmpty(languageId))
{
countries = countries
@@ -144,7 +145,7 @@ namespace Grand.Business.Common.Services.Directory
var query = from c in _countryRepository.Table
where countryIds.Contains(c.Id)
select c;
- var countries = await query.ToListAsync();
+ var countries = await query.ToListAsync2();
//sort by passed identifiers
var sortedCountries = new List<Country>();
foreach (string id in countryIds)
@@ -166,8 +167,7 @@ namespace Grand.Business.Common.Services.Directory
var key = string.Format(CacheKey.COUNTRIES_BY_TWOLETTER, twoLetterIsoCode);
return _cacheBase.GetAsync(key, () =>
{
- var filter = Builders<Country>.Filter.Eq(x => x.TwoLetterIsoCode, twoLetterIsoCode);
- return _countryRepository.Collection.Find(filter).FirstOrDefaultAsync();
+ return _countryRepository.Table.Where(x => x.TwoLetterIsoCode == twoLetterIsoCode).FirstOrDefaultAsync2();
});
}
@@ -181,8 +181,7 @@ namespace Grand.Business.Common.Services.Directory
var key = string.Format(CacheKey.COUNTRIES_BY_THREELETTER, threeLetterIsoCode);
return _cacheBase.GetAsync(key, () =>
{
- var filter = Builders<Country>.Filter.Eq(x => x.ThreeLetterIsoCode, threeLetterIsoCode);
- return _countryRepository.Collection.Find(filter).FirstOrDefaultAsync();
+ return _countryRepository.Table.Where(x => x.ThreeLetterIsoCode == threeLetterIsoCode).FirstOrDefaultAsync2();
});
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs b/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs
index 45622706b..4d60f6fca 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/CurrencyService.cs
@@ -7,8 +7,6 @@ using Grand.Infrastructure.Caching.Constants;
using Grand.Infrastructure.Extensions;
using Grand.SharedKernel;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -111,7 +109,7 @@ namespace Grand.Business.Common.Services.Directory
var query = from q in _currencyRepository.Table
where q.CurrencyCode.ToLowerInvariant() == currencyCode.ToLower()
select q;
- return query.FirstOrDefaultAsync();
+ return query.FirstOrDefaultAsync2();
});
}
@@ -126,12 +124,13 @@ namespace Grand.Business.Common.Services.Directory
string key = string.Format(CacheKey.CURRENCIES_ALL_KEY, showHidden);
var currencies = await _cacheBase.GetAsync(key, () =>
{
- var query = _currencyRepository.Table;
+ var query = from p in _currencyRepository.Table
+ select p;
if (!showHidden)
query = query.Where(c => c.Published);
query = query.OrderBy(c => c.DisplayOrder);
- return query.ToListAsync();
+ return query.ToListAsync2();
});
//store acl
diff --git a/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs b/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs
index 70c128936..9acc08a15 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/GroupService.cs
@@ -7,8 +7,6 @@ using Grand.Infrastructure.Caching.Constants;
using Grand.Infrastructure.Extensions;
using Grand.SharedKernel;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -96,8 +94,7 @@ namespace Grand.Business.Common.Services.Directory
string key = string.Format(CacheKey.CUSTOMERGROUPS_BY_SYSTEMNAME_KEY, systemName);
return _cacheBase.GetAsync(key, () =>
{
- var filter = Builders<CustomerGroup>.Filter.Eq(x => x.SystemName, systemName);
- return _customerGroupRepository.Collection.Find(filter).FirstOrDefaultAsync();
+ return _customerGroupRepository.Table.Where(x => x.SystemName == systemName).FirstOrDefaultAsync2();
});
}
@@ -220,7 +217,7 @@ namespace Grand.Business.Common.Services.Directory
var query = from cr in _customerGroupRepository.Table
orderby cr.Name
select cr;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
return customerGroups.Where(x => ids.Contains(x.Id)).ToList();
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs b/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs
index bbc0411aa..2b1ead6c6 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/HistoryService.cs
@@ -2,8 +2,6 @@ using Grand.Business.Common.Interfaces.Directory;
using Grand.Domain;
using Grand.Domain.Data;
using Grand.Domain.History;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -40,7 +38,7 @@ namespace Grand.Business.Common.Services.Directory
if (entity == null)
throw new ArgumentNullException(nameof(entity));
- var history = await _historyRepository.Table.Where(x => x.Object.Id == entity.Id).Select(x => (T)x.Object).ToListAsync();
+ var history = await _historyRepository.Table.Where(x => x.Object.Id == entity.Id).Select(x => (T)x.Object).ToListAsync2();
return history;
}
@@ -49,7 +47,7 @@ namespace Grand.Business.Common.Services.Directory
if (entity == null)
throw new ArgumentNullException(nameof(entity));
- var history = await _historyRepository.Table.Where(x => x.Object.Id == entity.Id).ToListAsync();
+ var history = await _historyRepository.Table.Where(x => x.Object.Id == entity.Id).ToListAsync2();
return history;
}
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/MeasureService.cs b/src/Business/Grand.Business.Common/Services/Directory/MeasureService.cs
index 6932fd6f0..e203997e2 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/MeasureService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/MeasureService.cs
@@ -6,8 +6,6 @@ using Grand.Domain.Data;
using Grand.Domain.Directory;
using Grand.SharedKernel;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -20,8 +18,6 @@ namespace Grand.Business.Common.Services.Directory
/// </summary>
public partial class MeasureService : IMeasureService
{
-
-
#region Fields
private readonly IRepository<MeasureDimension> _measureDimensionRepository;
@@ -105,7 +101,7 @@ namespace Grand.Business.Common.Services.Directory
var query = from md in _measureDimensionRepository.Table
orderby md.DisplayOrder
select md;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
}
@@ -280,7 +276,7 @@ namespace Grand.Business.Common.Services.Directory
var query = from mw in _measureWeightRepository.Table
orderby mw.DisplayOrder
select mw;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
}
@@ -439,7 +435,7 @@ namespace Grand.Business.Common.Services.Directory
var query = from md in _measureUnitRepository.Table
orderby md.DisplayOrder
select md;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
}
diff --git a/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs b/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
index 568586ac9..6f2543a6e 100644
--- a/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
+++ b/src/Business/Grand.Business.Common/Services/Directory/SearchTermService.cs
@@ -5,8 +5,6 @@ using Grand.Domain.Common;
using Grand.Domain.Data;
using Grand.Infrastructure.Extensions;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
@@ -78,7 +76,7 @@ namespace Grand.Business.Common.Services.Directory
where st.Keyword == keyword && st.StoreId == storeId
orderby st.Id
select st;
- return await query.FirstOrDefaultAsync();
+ return await query.FirstOrDefaultAsync2();
}
/// <summary>
diff --git a/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs b/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs
index 6d6bf48e4..edd00b7b3 100644
--- a/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs
+++ b/src/Business/Grand.Business.Common/Services/Localization/LanguageService.cs
@@ -5,8 +5,6 @@ using Grand.Infrastructure.Extensions;
using Grand.Domain.Data;
using Grand.Domain.Localization;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -60,12 +58,13 @@ namespace Grand.Business.Common.Services.Localization
string key = string.Format(CacheKey.LANGUAGES_ALL_KEY, showHidden);
var languages = await _cacheBase.GetAsync(key, () =>
{
- var query = _languageRepository.Table;
+ var query = from p in _languageRepository.Table
+ select p;
if (!showHidden)
query = query.Where(l => l.Published);
query = query.OrderBy(l => l.DisplayOrder);
- return query.ToListAsync();
+ return query.ToListAsync2();
});
//store acl
diff --git a/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs b/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
index 9420a986e..09ab5dd57 100644
--- a/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
+++ b/src/Business/Grand.Business.Common/Services/Localization/TranslationService.cs
@@ -6,8 +6,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.IO;
@@ -85,7 +83,7 @@ namespace Grand.Business.Common.Services.Localization
orderby lsr.Name
where lsr.LanguageId == languageId && lsr.Name == name
select lsr;
- var translateResource = query.FirstOrDefaultAsync();
+ var translateResource = query.FirstOrDefaultAsync2();
return translateResource;
}
@@ -96,8 +94,7 @@ namespace Grand.Business.Common.Services.Localization
/// <returns>Translate resources</returns>
public virtual IList<TranslationResource> GetAllResources(string languageId)
{
- var filter = Builders<TranslationResource>.Filter.Eq(x => x.LanguageId, languageId);
- return _translationRepository.Collection.Find(filter).ToList();
+ return _translationRepository.Table.Where(x=>x.LanguageId == languageId).ToList();
}
/// <summary>
@@ -301,7 +298,7 @@ namespace Grand.Business.Common.Services.Localization
//bulk insert
var resource = await (from l in _translationRepository.Table
where l.Name == name.ToLowerInvariant() && l.LanguageId == language.Id
- select l).FirstOrDefaultAsync();
+ select l).FirstOrDefaultAsync2();
if (resource != null)
{
diff --git a/src/Business/Grand.Business.Common/Services/Logging/CustomerActivityService.cs b/src/Business/Grand.Business.Common/Services/Logging/CustomerActivityService.cs
index 3da128365..0f39e07f2 100644
--- a/src/Business/Grand.Business.Common/Services/Logging/CustomerActivityService.cs
+++ b/src/Business/Grand.Business.Common/Services/Logging/CustomerActivityService.cs
@@ -8,8 +8,6 @@ using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using Grand.SharedKernel.Extensions;
using Microsoft.AspNetCore.Http;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -124,7 +122,7 @@ namespace Grand.Business.Common.Services.Logging
var query = from alt in _activityLogTypeRepository.Table
orderby alt.Name
select alt;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
/// <summary>
@@ -218,7 +216,9 @@ namespace Grand.Business.Common.Services.Logging
string ipAddress = null,
int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (!String.IsNullOrEmpty(comment))
query = query.Where(al => al.Comment != null && al.Comment.ToLower().Contains(comment.ToLower()));
if (createdOnFrom.HasValue)
@@ -249,35 +249,26 @@ namespace Grand.Business.Common.Services.Logging
DateTime? createdOnTo = null, string activityLogTypeId = "",
int pageIndex = 0, int pageSize = int.MaxValue)
{
+ var query = from p in _activityLogRepository.Table
+ select p;
- var builder = Builders<ActivityLog>.Filter;
- var filter = builder.Where(x => true);
if (createdOnFrom.HasValue)
- filter = filter & builder.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
+ query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
- filter = filter & builder.Where(al => createdOnTo.Value >= al.CreatedOnUtc);
+ query = query.Where(al => createdOnTo.Value >= al.CreatedOnUtc);
if (!String.IsNullOrEmpty(activityLogTypeId))
- filter = filter & builder.Where(al => activityLogTypeId == al.ActivityLogTypeId);
-
- var query = _activityLogRepository.Collection
- .Aggregate()
- .Match(filter)
- .Group(
- key => new { key.ActivityLogTypeId, key.EntityKeyId },
- g => new
- {
- Id = g.Key,
- Count = g.Count()
- })
- .Project(x => new ActivityStats
- {
- ActivityLogTypeId = x.Id.ActivityLogTypeId,
- EntityKeyId = x.Id.EntityKeyId,
- Count = x.Count
- })
- .SortByDescending(x => x.Count);
-
- return await PagedList<ActivityStats>.Create(query, pageIndex, pageSize);
+ query = query.Where(al => activityLogTypeId == al.ActivityLogTypeId);
+
+ var gquery = query.GroupBy(key=> new { key.ActivityLogTypeId, key.EntityKeyId })
+ .Select(g => new ActivityStats {
+ ActivityLogTypeId = g.Key.ActivityLogTypeId,
+ EntityKeyId = g.Key.EntityKeyId,
+ Count = g.Count(),
+ });
+
+ gquery = gquery.OrderByDescending(x => x.Count);
+
+ return await PagedList<ActivityStats>.Create(gquery, pageIndex, pageSize);
}
/// <summary>
/// Gets category activity log items
@@ -291,7 +282,9 @@ namespace Grand.Business.Common.Services.Logging
public virtual async Task<IPagedList<ActivityLog>> GetCategoryActivities(DateTime? createdOnFrom = null,
DateTime? createdOnTo = null, string categoryId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (createdOnFrom.HasValue)
query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
@@ -319,7 +312,9 @@ namespace Grand.Business.Common.Services.Logging
public virtual async Task<IPagedList<ActivityLog>> GetKnowledgebaseCategoryActivities(DateTime? createdOnFrom = null,
DateTime? createdOnTo = null, string categoryId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (createdOnFrom.HasValue)
query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
@@ -347,7 +342,9 @@ namespace Grand.Business.Common.Services.Logging
public virtual async Task<IPagedList<ActivityLog>> GetKnowledgebaseArticleActivities(DateTime? createdOnFrom = null,
DateTime? createdOnTo = null, string categoryId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (createdOnFrom.HasValue)
query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
@@ -374,7 +371,9 @@ namespace Grand.Business.Common.Services.Logging
public virtual async Task<IPagedList<ActivityLog>> GetBrandActivities(DateTime? createdOnFrom = null,
DateTime? createdOnTo = null, string brandId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (createdOnFrom.HasValue)
query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
@@ -402,7 +401,9 @@ namespace Grand.Business.Common.Services.Logging
public virtual async Task<IPagedList<ActivityLog>> GetCollectionActivities(DateTime? createdOnFrom = null,
DateTime? createdOnTo = null, string collectionId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (createdOnFrom.HasValue)
query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
@@ -430,7 +431,9 @@ namespace Grand.Business.Common.Services.Logging
public virtual async Task<IPagedList<ActivityLog>> GetProductActivities(DateTime? createdOnFrom = null,
DateTime? createdOnTo = null, string productId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _activityLogRepository.Table;
+ var query = from p in _activityLogRepository.Table
+ select p;
+
if (createdOnFrom.HasValue)
query = query.Where(al => createdOnFrom.Value <= al.CreatedOnUtc);
if (createdOnTo.HasValue)
@@ -461,7 +464,7 @@ namespace Grand.Business.Common.Services.Logging
/// </summary>
public virtual async Task ClearAllActivities()
{
- await _activityLogRepository.Collection.DeleteManyAsync(new MongoDB.Bson.BsonDocument());
+ await _activityLogRepository.ClearAsync();
}
#endregion
diff --git a/src/Business/Grand.Business.Common/Services/Logging/DefaultLogger.cs b/src/Business/Grand.Business.Common/Services/Logging/DefaultLogger.cs
index 529f81934..4b3863172 100644
--- a/src/Business/Grand.Business.Common/Services/Logging/DefaultLogger.cs
+++ b/src/Business/Grand.Business.Common/Services/Logging/DefaultLogger.cs
@@ -6,8 +6,6 @@ using Grand.Domain.Logging;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Net.Http.Headers;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -60,25 +58,23 @@ namespace Grand.Business.Common.Services.Logging
string message = "", LogLevel? logLevel = null,
int pageIndex = 0, int pageSize = int.MaxValue)
{
-
- var builder = Builders<Log>.Filter;
- var filter = builder.Where(c => true);
+ var query = from p in _logRepository.Table
+ select p;
if (fromUtc.HasValue)
- filter = filter & builder.Where(l => fromUtc.Value <= l.CreatedOnUtc);
+ query = query.Where(l => fromUtc.Value <= l.CreatedOnUtc);
if (toUtc.HasValue)
- filter = filter & builder.Where(l => toUtc.Value >= l.CreatedOnUtc);
+ query = query.Where(l => toUtc.Value >= l.CreatedOnUtc);
if (logLevel.HasValue)
{
- filter = filter & builder.Where(l => logLevel.Value == l.LogLevelId);
+ query = query.Where(l => logLevel.Value == l.LogLevelId);
}
- if (!String.IsNullOrEmpty(message))
- filter = filter & builder.Where(l => l.ShortMessage.ToLower().Contains(message.ToLower()) || l.FullMessage.ToLower().Contains(message.ToLower()));
-
- var builderSort = Builders<Log>.Sort.Descending(x => x.CreatedOnUtc);
- var query = _logRepository.Collection;
+ if (!string.IsNullOrEmpty(message))
+ query = query.Where(l => l.ShortMessage.ToLower().Contains(message.ToLower()) || l.FullMessage.ToLower().Contains(message.ToLower()));
- var logs = await PagedList<Log>.Create(query, filter, builderSort, pageIndex, pageSize);
+ query = query.OrderByDescending(x => x.CreatedOnUtc);
+
+ var logs = await PagedList<Log>.Create(query, pageIndex, pageSize);
return logs;
}
@@ -107,7 +103,7 @@ namespace Grand.Business.Common.Services.Logging
where logIds.Contains(l.Id)
select l;
- var logItems = await query.ToListAsync();
+ var logItems = await query.ToListAsync2();
var sortedLogItems = new List<Log>();
foreach (string id in logIds)
{
@@ -178,7 +174,7 @@ namespace Grand.Business.Common.Services.Logging
/// </summary>
public virtual async Task ClearLog()
{
- await _logRepository.Collection.DeleteManyAsync(new MongoDB.Bson.BsonDocument());
+ await _logRepository.ClearAsync();
}
#endregion
diff --git a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
index e0773bf38..81107bf2e 100644
--- a/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
+++ b/src/Business/Grand.Business.Common/Services/Security/PermissionService.cs
@@ -5,8 +5,6 @@ using Grand.Infrastructure.Caching.Constants;
using Grand.Domain.Customers;
using Grand.Domain.Data;
using Grand.Domain.Permissions;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -72,7 +70,7 @@ namespace Grand.Business.Common.Services.Security
string key = string.Format(CacheKey.PERMISSIONS_ALLOWED_KEY, customerGroup.Id, permissionSystemName);
return await _cacheBase.GetAsync(key, async () =>
{
- var permissionRecord = await _permissionRepository.Table.FirstOrDefaultAsync(x => x.SystemName == permissionSystemName);
+ var permissionRecord = await _permissionRepository.Table.Where(x => x.SystemName == permissionSystemName).FirstOrDefaultAsync2();
return permissionRecord?.CustomerGroups.Contains(customerGroup.Id) ?? false;
});
}
@@ -120,7 +118,7 @@ namespace Grand.Business.Common.Services.Security
orderby pr.Id
select pr;
- return await query.FirstOrDefaultAsync();
+ return await query.FirstOrDefaultAsync2();
}
/// <summary>
@@ -132,7 +130,7 @@ namespace Grand.Business.Common.Services.Security
var query = from pr in _permissionRepository.Table
orderby pr.Name
select pr;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
/// <summary>
@@ -230,7 +228,7 @@ namespace Grand.Business.Common.Services.Security
public virtual async Task<IList<PermissionAction>> GetPermissionActions(string systemName, string customeroleId)
{
return await _permissionActionRepository.Table
- .Where(x => x.SystemName == systemName && x.CustomerGroupId == customeroleId).ToListAsync();
+ .Where(x => x.SystemName == systemName && x.CustomerGroupId == customeroleId).ToListAsync2();
}
/// <summary>
@@ -286,8 +284,8 @@ namespace Grand.Business.Common.Services.Security
var key = string.Format(CacheKey.PERMISSIONS_ALLOWED_ACTION_KEY, group.Id, permissionSystemName, permissionActionName);
var permissionAction = await _cacheBase.GetAsync(key, async () =>
{
- return await _permissionActionRepository.Table
- .FirstOrDefaultAsync(x => x.SystemName == permissionSystemName && x.CustomerGroupId == group.Id && x.Action == permissionActionName);
+ return await _permissionActionRepository.Table.Where(x => x.SystemName == permissionSystemName && x.CustomerGroupId == group.Id && x.Action == permissionActionName)
+ .FirstOrDefaultAsync2();
});
if (permissionAction != null)
return false;
diff --git a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
index 1ee70911a..34041670b 100644
--- a/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
+++ b/src/Business/Grand.Business.Common/Services/Seo/SlugService.cs
@@ -5,8 +5,6 @@ using Grand.Domain.Seo;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
using Grand.Infrastructure.Configuration;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -58,7 +56,7 @@ namespace Grand.Business.Common.Services.Seo
return await _cacheBase.GetAsync(key, async () =>
{
var query = _urlEntityRepository.Table;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
});
}
@@ -135,7 +133,7 @@ namespace Grand.Business.Common.Services.Seo
where ur.Slug == slug
orderby ur.IsActive
select ur;
- return await query.FirstOrDefaultAsync();
+ return await query.FirstOrDefaultAsync2();
}
/// <summary>
@@ -183,7 +181,8 @@ namespace Grand.Business.Common.Services.Seo
public virtual async Task<IPagedList<EntityUrl>> GetAllEntityUrl(string slug = "", bool? active = null, int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _urlEntityRepository.Table;
+ var query = from p in _urlEntityRepository.Table
+ select p;
if (!string.IsNullOrWhiteSpace(slug))
query = query.Where(ur => ur.Slug.Contains(slug.ToLowerInvariant()));
@@ -235,7 +234,7 @@ namespace Grand.Business.Common.Services.Seo
ur.LanguageId == languageId &&
ur.IsActive
select ur.Slug;
- var slug = await query.FirstOrDefaultAsync();
+ var slug = await query.FirstOrDefaultAsync2();
if (slug == null)
slug = "";
return slug;
@@ -264,7 +263,7 @@ namespace Grand.Business.Common.Services.Seo
ur.LanguageId == languageId
select ur;
- var allUrlEntity = await query.ToListAsync();
+ var allUrlEntity = await query.ToListAsync2();
var activeUrlEntity = allUrlEntity.FirstOrDefault(x => x.IsActive);
if (!string.IsNullOrWhiteSpace(slug))
diff --git a/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs b/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
index 88860a5b8..602807752 100644
--- a/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
+++ b/src/Business/Grand.Business.Common/Services/Stores/StoreService.cs
@@ -5,11 +5,10 @@ using Grand.Infrastructure.Extensions;
using Grand.Domain.Data;
using Grand.Domain.Stores;
using MediatR;
-using MongoDB.Bson;
-using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+using System.Linq;
namespace Grand.Business.Common.Services.Stores
{
@@ -59,7 +58,7 @@ namespace Grand.Business.Common.Services.Stores
{
_allStores = await _cacheBase.GetAsync(CacheKey.STORES_ALL_KEY, () =>
{
- return _storeRepository.Collection.Find(new BsonDocument()).SortBy(x => x.DisplayOrder).ToListAsync();
+ return _storeRepository.Table.OrderBy(x => x.DisplayOrder).ToListAsync2();
});
}
return _allStores;
@@ -75,7 +74,7 @@ namespace Grand.Business.Common.Services.Stores
{
_allStores = _cacheBase.Get(CacheKey.STORES_ALL_KEY, () =>
{
- return _storeRepository.Collection.Find(new BsonDocument()).SortBy(x => x.DisplayOrder).ToList();
+ return _storeRepository.Table.OrderBy(x => x.DisplayOrder).ToList();
});
}
return _allStores;
diff --git a/src/Business/Grand.Business.System/Commands/Handlers/Catalog/SendNotificationsToSubscribersCommandHandler.cs b/src/Business/Grand.Business.System/Commands/Handlers/Catalog/SendNotificationsToSubscribersCommandHandler.cs
index 7d473ee2e..2e73d18e5 100644
--- a/src/Business/Grand.Business.System/Commands/Handlers/Catalog/SendNotificationsToSubscribersCommandHandler.cs
+++ b/src/Business/Grand.Business.System/Commands/Handlers/Catalog/SendNotificationsToSubscribersCommandHandler.cs
@@ -7,8 +7,6 @@ using Grand.Domain.Customers;
using Grand.Domain.Data;
using Grand.SharedKernel.Extensions;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -68,7 +66,7 @@ namespace Grand.Business.System.Commands.Handlers.Catalog
{
var query = await _outOfStockSubscriptionRepository.Table
.Where(biss => biss.ProductId == productId)
- .OrderByDescending(biss => biss.CreatedOnUtc).ToListAsync();
+ .OrderByDescending(biss => biss.CreatedOnUtc).ToListAsync2();
//warehouse
if (!string.IsNullOrEmpty(warehouseId))