Browse Source

Use async methods to get DbContext, Queryable, and DbSet

pull/229/head
gdlcf88 3 years ago
parent
commit
579056c8e6
  1. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistoryRepository.cs
  2. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductHistories/ProductHistoryRepository.cs
  3. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductInventories/ProductInventoryRepository.cs
  4. 2
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/Products/ProductViewRepository.cs
  5. 1
      plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/GrantedStores/GrantedStoreController.cs
  6. 2
      plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Installer/EasyAbp.EShop.Plugins.Booking.Installer.csproj
  7. 2
      plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Web/BookingWebAutoMapperProfile.cs
  8. 2
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponAppService.cs
  9. 3
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Domain/EasyAbp/EShop/Plugins/Coupons/Coupons/ICouponRepository.cs
  10. 6
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponRepository.cs
  11. 1
      plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.HttpApi/EasyAbp/EShop/Plugins/Coupons/CouponTemplates/CouponTemplateController.cs
  12. 2
      samples/EShopSample/aspnet-core/test/EShopSample.Web.Tests/EShopSampleWebTestModule.cs

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductDetailHistories/ProductDetailHistoryRepository.cs

@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories
public async Task<ProductDetailHistory> GetAsync(Guid productDetailId, DateTime modificationTime, CancellationToken cancellationToken = default)
{
var entity = await GetQueryable()
var entity = await (await GetQueryableAsync())
.Where(x => x.ModificationTime == modificationTime && x.ProductDetailId == productDetailId)
.FirstOrDefaultAsync(cancellationToken);

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductHistories/ProductHistoryRepository.cs

@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.ProductHistories
public async Task<ProductHistory> GetAsync(Guid productId, DateTime modificationTime, CancellationToken cancellationToken = default)
{
var entity = await GetQueryable()
var entity = await (await GetQueryableAsync())
.Where(x => x.ModificationTime == modificationTime && x.ProductId == productId)
.FirstOrDefaultAsync(cancellationToken);

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/ProductInventories/ProductInventoryRepository.cs

@ -18,7 +18,7 @@ namespace EasyAbp.EShop.Products.ProductInventories
public async Task<InventoryDataModel> GetInventoryDataAsync(Guid productSkuId, CancellationToken cancellationToken = default)
{
return await GetQueryable()
return await (await GetQueryableAsync())
.Where(x => x.ProductSkuId == productSkuId)
.Select(x => new InventoryDataModel
{

2
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.EntityFrameworkCore/EasyAbp/EShop/Products/Products/ProductViewRepository.cs

@ -20,7 +20,7 @@ namespace EasyAbp.EShop.Products.Products
public virtual async Task<IQueryable<ProductView>> GetQueryableAsync(Guid categoryId)
{
return await JoinProductCategoriesAsync(DbSet, categoryId);
return await JoinProductCategoriesAsync(await GetDbSetAsync(), categoryId);
}
public virtual async Task<IQueryable<ProductView>> WithDetailsAsync(Guid categoryId)

1
plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.HttpApi/EasyAbp/EShop/Plugins/Booking/GrantedStores/GrantedStoreController.cs

@ -4,7 +4,6 @@ using Volo.Abp.Application.Dtos;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Plugins.Booking.GrantedStores
{

2
plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Installer/EasyAbp.EShop.Plugins.Booking.Installer.csproj

@ -3,7 +3,7 @@
<Import Project="..\..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<RootNamespace />
</PropertyGroup>

2
plugins/Booking/src/EasyAbp.EShop.Plugins.Booking.Web/BookingWebAutoMapperProfile.cs

@ -1,9 +1,7 @@
using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos;
using EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssets.ProductAsset.ViewModels;
using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos;
using EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssets.ProductAssetPeriod.ViewModels;
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos;
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos;
using AutoMapper;
using EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssetCategories.ProductAssetCategory.ViewModels;
using EasyAbp.EShop.Plugins.Booking.GrantedStores.Dtos;

2
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Application/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponAppService.cs

@ -38,7 +38,7 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons
protected override async Task<IQueryable<Coupon>> CreateFilteredQueryAsync(GetCouponListInput input)
{
return (input.AvailableOnly
? _repository.GetAvailableCouponQueryable(Clock)
? await _repository.GetAvailableCouponQueryableAsync(Clock)
: await _repository.GetQueryableAsync())
.WhereIf(input.UserId.HasValue, x => x.UserId == input.UserId.Value)
.WhereIf(!input.AvailableOnly && !input.IncludesUsed, x => !x.UsedTime.HasValue)

3
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.Domain/EasyAbp/EShop/Plugins/Coupons/Coupons/ICouponRepository.cs

@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Timing;
@ -7,6 +8,6 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons
{
public interface ICouponRepository : IRepository<Coupon, Guid>
{
IQueryable<Coupon> GetAvailableCouponQueryable(IClock clock);
Task<IQueryable<Coupon>> GetAvailableCouponQueryableAsync(IClock clock);
}
}

6
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.EntityFrameworkCore/EasyAbp/EShop/Plugins/Coupons/Coupons/CouponRepository.cs

@ -17,14 +17,14 @@ namespace EasyAbp.EShop.Plugins.Coupons.Coupons
{
}
public virtual IQueryable<Coupon> GetAvailableCouponQueryable(IClock clock)
public virtual async Task<IQueryable<Coupon>> GetAvailableCouponQueryableAsync(IClock clock)
{
var now = clock.Now;
return DbSet
return (await GetDbSetAsync())
.Where(x => x.ExpirationTime > now)
.Join(
DbContext.CouponTemplates.Where(x => !x.UsableBeginTime.HasValue || x.UsableBeginTime.Value <= now),
(await GetDbContextAsync()).CouponTemplates.Where(x => !x.UsableBeginTime.HasValue || x.UsableBeginTime.Value <= now),
coupon => coupon.CouponTemplateId,
couponTemplate => couponTemplate.Id,
(coupon, couponTemplate) => coupon

1
plugins/Coupons/src/EasyAbp.EShop.Plugins.Coupons.HttpApi/EasyAbp/EShop/Plugins/Coupons/CouponTemplates/CouponTemplateController.cs

@ -4,7 +4,6 @@ using Volo.Abp.Application.Dtos;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Plugins.Coupons.CouponTemplates
{

2
samples/EShopSample/aspnet-core/test/EShopSample.Web.Tests/EShopSampleWebTestModule.cs

@ -87,7 +87,7 @@ namespace EShopSample
}
});
app.UseVirtualFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

Loading…
Cancel
Save