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

KrzysztofPajak932dd67d4165
diff --git a/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
index 8c2c7dcf9..fadd9bc70 100644
--- a/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs
@@ -15,8 +15,6 @@ using Grand.Infrastructure.Extensions;
using Grand.SharedKernel.Extensions;
using MediatR;
using Microsoft.AspNetCore.Mvc;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -322,7 +320,7 @@ namespace Grand.Business.Authentication.Services
if (parameters == null)
throw new ArgumentNullException(nameof(parameters));
- var associationRecord = await _externalAuthenticationRecordRepository.Table.FirstOrDefaultAsync(record =>
+ var associationRecord = await _externalAuthenticationRecordRepository.FirstOrDefaultAsync(record =>
record.ExternalIdentifier.Equals(parameters.Identifier) && record.ProviderSystemName.Equals(parameters.ProviderSystemName));
if (associationRecord == null)
@@ -338,7 +336,7 @@ namespace Grand.Business.Authentication.Services
var query = from p in _externalAuthenticationRecordRepository.Table
where p.CustomerId == customer.Id
select p;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetPersonalizedProductsQueryHandler.cs b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetPersonalizedProductsQueryHandler.cs
index be212b136..5b67503b2 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetPersonalizedProductsQueryHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetPersonalizedProductsQueryHandler.cs
@@ -6,8 +6,6 @@ using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Data;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -41,7 +39,7 @@ namespace Grand.Business.Catalog.Queries.Handlers
orderby cr.DisplayOrder
select cr.ProductId;
- var productIds = await query.Take(request.ProductsNumber).ToListAsync();
+ var productIds = await query.Take(request.ProductsNumber).ToListAsync2();
var products = new List<Product>();
var ids = await _productService.GetProductsByIds(productIds.Distinct().ToArray());
diff --git a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs
index babd76852..8976e4b67 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs
@@ -6,8 +6,6 @@ using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Data;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -41,7 +39,7 @@ namespace Grand.Business.Catalog.Queries.Handlers
orderby cr.DisplayOrder
select cr.ProductId;
- var productIds = await query.ToListAsync();
+ var productIds = await query.ToListAsync2();
var products = new List<Product>();
var ids = await _productService.GetProductsByIds(productIds.Distinct().ToArray());
diff --git a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSuggestedProductsQueryHandler.cs b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSuggestedProductsQueryHandler.cs
index 7a060c6a5..787d81445 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSuggestedProductsQueryHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetSuggestedProductsQueryHandler.cs
@@ -6,8 +6,6 @@ using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Domain.Data;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@@ -44,7 +42,7 @@ namespace Grand.Business.Catalog.Queries.Handlers
orderby cr.DisplayOrder
select cr.ProductId;
- var productIds = await query.Take(request.ProductsNumber).ToListAsync();
+ var productIds = await query.Take(request.ProductsNumber).ToListAsync2();
var products = new List<Product>();
var ids = await _productService.GetProductsByIds(productIds.Distinct().ToArray());
diff --git a/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs
index f2ac5d6af..96ddd2fb7 100644
--- a/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.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;
@@ -59,7 +57,7 @@ namespace Grand.Business.Catalog.Services.Brands
var query = from pt in _brandLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs b/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
index 0a4ccbd80..9aa25dc21 100644
--- a/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Brands/BrandService.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;
@@ -172,7 +170,7 @@ namespace Grand.Business.Catalog.Services.Brands
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
#endregion
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs
index 84e19b0a2..973e93026 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs
@@ -3,8 +3,6 @@ using Grand.Infrastructure.Extensions;
using Grand.Domain.Catalog;
using Grand.Domain.Data;
using MediatR;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -59,7 +57,7 @@ namespace Grand.Business.Catalog.Services.Categories
var query = from pt in _categoryLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
index 29988d329..e09807a8b 100644
--- a/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs
@@ -11,8 +11,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;
@@ -139,7 +137,7 @@ namespace Grand.Business.Catalog.Services.Categories
select p;
}
}
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
/// <summary>
@@ -157,29 +155,30 @@ namespace Grand.Business.Catalog.Services.Categories
string key = string.Format(CacheKey.CATEGORIES_BY_PARENT_CATEGORY_ID_KEY, parentCategoryId, showHidden, customer.Id, storeId, includeAllLevels);
return await _cacheBase.GetAsync(key, async () =>
{
- var builder = Builders<Category>.Filter;
- var filter = builder.Where(c => c.ParentCategoryId == parentCategoryId);
+ var query = _categoryRepository.Table.Where(c => c.ParentCategoryId == parentCategoryId);
if (!showHidden)
- filter &= builder.Where(c => c.Published);
+ query = query.Where(c => c.Published);
if (!showHidden && (!CommonHelper.IgnoreAcl || !CommonHelper.IgnoreStoreLimitations))
{
if (!showHidden && !CommonHelper.IgnoreAcl)
{
- //Limited to customer group (access control list)
- var allowedCustomerGroupsIds = customer.GetCustomerGroupIds();
- filter &= (builder.AnyIn(x => x.CustomerGroups, allowedCustomerGroupsIds) | builder.Where(x => !x.LimitedToGroups));
-
+ //Limited to customer groups rules
+ var allowedCustomerGroupsIds = _workContext.CurrentCustomer.GetCustomerGroupIds();
+ query = from p in query
+ where !p.LimitedToGroups || allowedCustomerGroupsIds.Any(x => p.CustomerGroups.Contains(x))
+ select p;
}
if (!CommonHelper.IgnoreStoreLimitations)
{
- //Limited to stores rule
- var currentStoreId = new List<string> { storeId };
- filter &= (builder.AnyIn(x => x.Stores, currentStoreId) | builder.Where(x => !x.LimitedToStores));
+ //Limited to stores rules
+ query = from p in query
+ where !p.LimitedToStores || p.Stores.Contains(storeId)
+ select p;
}
}
- var categories = _categoryRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder).ToList();
+ var categories = query.OrderBy(x => x.DisplayOrder).ToList();
if (includeAllLevels)
{
var childCategories = new List<Category>();
@@ -201,12 +200,10 @@ namespace Grand.Business.Catalog.Services.Categories
/// <returns>Categories</returns>
public virtual async Task<IList<Category>> GetAllCategoriesDisplayedOnHomePage(bool showHidden = false)
{
- var builder = Builders<Category>.Filter;
- var filter = builder.Eq(x => x.Published, true);
- filter &= builder.Eq(x => x.ShowOnHomePage, true);
- var query = _categoryRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder);
-
- var categories = await query.ToListAsync();
+ var query = _categoryRepository.Table
+ .Where(x => x.Published && x.ShowOnHomePage)
+ .OrderBy(x => x.DisplayOrder);
+ var categories = await query.ToListAsync2();
if (!showHidden)
{
categories = categories
@@ -224,12 +221,11 @@ namespace Grand.Business.Catalog.Services.Categories
/// <returns>Categories</returns>
public virtual async Task<IList<Category>> GetAllCategoriesFeaturedProductsOnHomePage(bool showHidden = false)
{
- var builder = Builders<Category>.Filter;
- var filter = builder.Eq(x => x.Published, true);
- filter &= builder.Eq(x => x.FeaturedProductsOnHomePage, true);
- var query = _categoryRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder);
+ var query = _categoryRepository.Table
+ .Where(x => x.Published && x.FeaturedProductsOnHomePage)
+ .OrderBy(x => x.DisplayOrder);
- var categories = await query.ToListAsync();
+ var categories = await query.ToListAsync2();
if (!showHidden)
{
categories = categories
@@ -246,11 +242,11 @@ namespace Grand.Business.Catalog.Services.Categories
/// <returns>Categories</returns>
public virtual async Task<IList<Category>> GetAllCategoriesSearchBox()
{
- var builder = Builders<Category>.Filter;
- var filter = builder.Eq(x => x.Published, true);
- filter &= builder.Eq(x => x.ShowOnSearchBox, true);
- var query = _categoryRepository.Collection.Find(filter).SortBy(x => x.SearchBoxDisplayOrder);
- var categories = (await query.ToListAsync())
+ var query = _categoryRepository.Table
+ .Where(x => x.Published && x.ShowOnSearchBox)
+ .OrderBy(x => x.SearchBoxDisplayOrder);
+
+ var categories = (await query.ToListAsync2())
.Where(c => _aclService.Authorize(c, _workContext.CurrentCustomer) && _aclService.Authorize(c, _workContext.CurrentStore.Id))
.ToList();
@@ -380,7 +376,7 @@ namespace Grand.Business.Catalog.Services.Categories
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
/// <summary>
diff --git a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs
index 92bc6d842..21878010e 100644
--- a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.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;
@@ -59,7 +57,7 @@ namespace Grand.Business.Catalog.Services.Collections
var query = from pt in _collectionLayoutRepository.Table
orderby pt.DisplayOrder
select pt;
- return query.ToListAsync();
+ return query.ToListAsync2();
});
}
diff --git a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
index c09c18bf6..1d6f234c1 100644
--- a/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs
@@ -10,8 +10,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;
@@ -110,12 +108,9 @@ namespace Grand.Business.Catalog.Services.Collections
/// <returns>Collections</returns>
public virtual async Task<IList<Collection>> GetAllCollectionFeaturedProductsOnHomePage(bool showHidden = false)
{
- var builder = Builders<Collection>.Filter;
- var filter = builder.Eq(x => x.Published, true);
- filter = filter & builder.Eq(x => x.FeaturedProductsOnHomePage, true);
- var query = _collectionRepository.Collection.Find(filter).SortBy(x => x.DisplayOrder);
+ var query = _collectionRepository.Table.Where(x=>x.Published && x.FeaturedProductsOnHomePage).OrderBy(x => x.DisplayOrder);
- var collections = await query.ToListAsync();
+ var collections = await query.ToListAsync2();
if (!showHidden)
{
collections = collections
@@ -203,7 +198,7 @@ namespace Grand.Business.Catalog.Services.Collections
where c.AppliedDiscounts.Any(x => x == discountId)
select c;
- return await query.ToListAsync();
+ return await query.ToListAsync2();
}
#endregion
diff --git a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
index dce78aa73..9020a7aa2 100644
--- a/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
+++ b/src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs
@@ -14,8 +14,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;
@@ -94,7 +92,8 @@ namespace Grand.Business.Catalog.Services.Discounts
string key = string.Format(CacheKey.DISCOUNTS_ALL_KEY, showHidden, storeId, currencyCode, couponCode, discountName);
var result = await _cacheBase.GetAsync(key, () =>
{
- var query = _discountRepository.Table;
+ var query = from m in _discountRepository.Table
+ select m;
if (!showHidden)
{
var nowUtc = DateTime.UtcNow;
@@ -126,7 +125,7 @@ namespace Grand.Business.Catalog.Services.Discounts
}
query = query.OrderBy(d => d.Name);
- var discounts = query.ToListAsync();
+ var discounts = query.ToListAsync2();
return discounts;
});
if (discountType.HasValue)
@@ -261,9 +260,7 @@ namespace Grand.Business.Catalog.Services.Discounts
if (String.IsNullOrWhiteSpace(couponCode))
return null;
- var builder = Builders<DiscountCoupon>.Filter;
- var filter = builder.Eq(x => x.CouponCode, couponCode);
- var query = await _discountCouponRepository.Collection.FindAsync(filter);
+ var query = await _discountCouponRepository.Table.Where(x => x.CouponCode == couponCode).ToListAsync2();
var coupon = query.FirstOrDefault();
if (coupon == null)
@@ -284,13 +281,15 @@ namespace Grand.Business.Catalog.Services.Discounts
if (String.IsNullOrWhiteSpace(couponCode))
return false;
- var builder = Builders<DiscountCoupon>.Filter;
- var filter = builder.Eq(x => x.CouponCode, couponCode);
- filter &= builder.Eq(x => x.DiscountId, discountId);
+ var query = _discountCouponRepository.Table.Where(x => x.CouponCode == couponCode
+ && x.DiscountId == discountId);
+
if (used.HasValue)
- filter &= builder.Eq(x => x.Used, used.Value);
- var query = await _discountCouponRepository.Collection.FindAsync(filter);
- if (query.Any())
+ query = query.Where(x => x.Used == used.Value);
+
+ var result = await query.ToListAsync2();
+
+ if (result.Any())
return true;
else
return false;
@@ -305,11 +304,13 @@ namespace Grand.Business.Catalog.Services.Discounts
/// <returns></returns>
public virtual async Task<IPagedList<DiscountCoupon>> GetAllCouponCodesByDiscountId(string discountId, int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _discountCouponRepository.Table;
+ var query = from d in _discountCouponRepository.Table
+ select d;
- if (!String.IsNullOrEmpty(discountId))
+ if (!string.IsNullOrEmpty(discountId))
query = query.Where(duh => duh.DiscountId == discountId);
query = query.OrderByDescending(c => c.CouponCode);
+
return await PagedList<DiscountCoupon>.Create(query, pageIndex, pageSize);
}
@@ -331,9 +332,7 @@ namespace Grand.Business.Catalog.Services.Discounts
/// <returns></returns>
public async Task<DiscountCoupon> GetDiscountCodeByCode(string couponCode)
{
- var builder = Builders<DiscountCoupon>.Filter;
- var filter = builder.Eq(x => x.CouponCode, couponCode);
- var query = await _discountCouponRepository.Collection.FindAsync(filter);
+ var query = await _discountCouponRepository.Table.Where(x => x.CouponCode == couponCode).ToListAsync2();
return query.FirstOrDefault();
}
@@ -388,7 +387,7 @@ namespace Grand.Business.Catalog.Services.Discounts
/// <param name="orderId"></param>
public virtual async Task CancelDiscount(string orderId)
{
- var discountUsage = await _discountUsageHistoryRepository.Table.Where(x => x.OrderId == orderId).ToListAsync();
+ var discountUsage = await _discountUsageHistoryRepository.Table.Where(x => x.OrderId == orderId).ToListAsync2();
foreach (var item in discountUsage)
{
await DiscountCouponSetAsUsed(item.CouponCode, false);
@@ -610,17 +609,19 @@ namespace Grand.Business.Catalog.Services.Discounts
string customerId = "", string orderId = "", bool? canceled = null,
int pageIndex = 0, int pageSize = int.MaxValue)
{
- var query = _discountUsageHistoryRepository.Table;
+ var query = from d in _discountUsageHistoryRepository.Table
+ select d;
- if (!String.IsNullOrEmpty(discountId))
+ if (!string.IsNullOrEmpty(discountId))
query = query.Where(duh => duh.DiscountId == discountId);
- if (!String.IsNullOrEmpty(customerId))
+ if (!string.IsNullOrEmpty(customerId))
query = query.Where(duh => duh.CustomerId == customerId);
- if (!String.IsNullOrEmpty(orderId))
+ if (!string.IsNullOrEmpty(orderId))
query = query.Where(duh => duh.OrderId == orderId);
if (canceled.HasValue)
query = query.Where(duh => duh.Canceled == canceled.Value);
query = query.OrderByDescending(c => c.CreatedOnUtc);
+
return await PagedList<DiscountUsageHistory>.Create(query, pageIndex, pageSize);
}
diff --git a/src/Business/Grand.Business.System/Services/Admin/AdminSiteMapService.cs b/src/Business/Grand.Business.System/Services/Admin/AdminSiteMapService.cs
index 3357859cd..01d9c7ca2 100644
--- a/src/Business/Grand.Business.System/Services/Admin/AdminSiteMapService.cs
+++ b/src/Business/Grand.Business.System/Services/Admin/AdminSiteMapService.cs
@@ -3,8 +3,6 @@ using Grand.Business.System.Utilities;
using Grand.Infrastructure.Caching;
using Grand.Domain.Admin;
using Grand.Domain.Data;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -31,7 +29,7 @@ namespace Grand.Business.System.Services.Admin
var query = from c in _adminSiteMapRepository.Table
select c;
- var list = await query.ToListAsync();
+ var list = await query.ToListAsync2();
if (list.Any())
return list;
else
diff --git a/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs b/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs
index b369c3a08..490812508 100644
--- a/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs
+++ b/src/Business/Grand.Business.System/Services/BackgroundServices/ScheduleTasks/ScheduleTaskService.cs
@@ -1,8 +1,6 @@
using Grand.Business.System.Interfaces.ScheduleTasks;
using Grand.Domain.Data;
using Grand.Domain.Tasks;
-using MongoDB.Driver;
-using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -47,15 +45,11 @@ namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks
/// <returns>Task</returns>
public virtual Task<ScheduleTask> GetTaskByType(string type)
{
- if (String.IsNullOrWhiteSpace(type))
+ if (string.IsNullOrWhiteSpace(type))
return Task.FromResult<ScheduleTask>(null);
- var query = _taskRepository.Table;
-
- query = query.Where(st => st.Type == type);
- query = query.OrderByDescending(t => t.Id);
-
- return query.FirstOrDefaultAsync();
+ var query = _taskRepository.Table.Where(st => st.Type == type).OrderByDescending(t => t.Id);
+ return query.FirstOrDefaultAsync2();
}
/// <summary>
@@ -65,7 +59,7 @@ namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks
/// <returns>Tasks</returns>
public virtual async Task<IList<ScheduleTask>> GetAllTasks()
{
- return await _taskRepository.Table.ToListAsync();
+ return await _taskRepository.Table.ToListAsync2();
}
/// <summary>