mirror of https://github.com/EasyAbp/EShop.git
62 changed files with 6521 additions and 163 deletions
@ -1,36 +1,187 @@ |
|||||
using System.Threading.Tasks; |
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Security.Principal; |
||||
|
using System.Threading.Tasks; |
||||
|
using EasyAbp.BookingService.AssetOccupancies; |
||||
|
using EasyAbp.BookingService.AssetOccupancies.Dtos; |
||||
|
using EasyAbp.BookingService.PeriodSchemes; |
||||
using EasyAbp.EShop.Orders; |
using EasyAbp.EShop.Orders; |
||||
|
using EasyAbp.EShop.Orders.Orders.Dtos; |
||||
using EasyAbp.EShop.Payments.Payments; |
using EasyAbp.EShop.Payments.Payments; |
||||
|
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories; |
||||
|
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; |
||||
|
using EasyAbp.EShop.Plugins.Booking.ProductAssets; |
||||
|
using EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos; |
||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
|
using Volo.Abp; |
||||
|
|
||||
namespace EasyAbp.EShop.Payments.Booking.Authorization |
namespace EasyAbp.EShop.Payments.Booking.Authorization |
||||
{ |
{ |
||||
public class BookingPaymentCreationAuthorizationHandler : PaymentCreationAuthorizationHandler |
public class BookingPaymentCreationAuthorizationHandler : PaymentCreationAuthorizationHandler |
||||
{ |
{ |
||||
public BookingPaymentCreationAuthorizationHandler() |
private readonly IPeriodSchemeAppService _periodSchemeAppService; |
||||
|
private readonly IProductAssetAppService _productAssetAppService; |
||||
|
private readonly IProductAssetCategoryAppService _productAssetCategoryAppService; |
||||
|
private readonly IAssetOccupancyAppService _assetOccupancyAppService; |
||||
|
|
||||
|
public BookingPaymentCreationAuthorizationHandler( |
||||
|
IPeriodSchemeAppService periodSchemeAppService, |
||||
|
IProductAssetAppService productAssetAppService, |
||||
|
IProductAssetCategoryAppService productAssetCategoryAppService, |
||||
|
IAssetOccupancyAppService assetOccupancyAppService) |
||||
{ |
{ |
||||
|
_periodSchemeAppService = periodSchemeAppService; |
||||
|
_productAssetAppService = productAssetAppService; |
||||
|
_productAssetCategoryAppService = productAssetCategoryAppService; |
||||
|
_assetOccupancyAppService = assetOccupancyAppService; |
||||
} |
} |
||||
|
|
||||
protected override async Task HandlePaymentCreationAsync(AuthorizationHandlerContext context, |
protected override async Task HandlePaymentCreationAsync(AuthorizationHandlerContext context, |
||||
PaymentOperationAuthorizationRequirement requirement, PaymentCreationResource resource) |
PaymentOperationAuthorizationRequirement requirement, PaymentCreationResource resource) |
||||
{ |
{ |
||||
foreach (var order in resource.Orders) |
foreach (var order in resource.Orders) |
||||
{ |
{ |
||||
foreach (var orderLine in order.OrderLines) |
if (await IsBookingOrderValidAsync(context, order)) |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
context.Fail(); |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<bool> IsBookingOrderValidAsync(AuthorizationHandlerContext context, OrderDto order) |
||||
|
{ |
||||
|
var bookingOrderLines = order.OrderLines.Where(x => x.FindBookingAssetId() is not null).ToList(); |
||||
|
|
||||
|
if (!bookingOrderLines.Any()) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
var models = new List<OccupyAssetInfoModel>(); |
||||
|
var byCategoryModels = new List<OccupyAssetByCategoryInfoModel>(); |
||||
|
|
||||
|
foreach (var orderLine in bookingOrderLines) |
||||
|
{ |
||||
|
if (!await IsPeriodInfoValidAsync(orderLine)) |
||||
{ |
{ |
||||
var assetId = orderLine.FindBookingAssetId(); |
return false; |
||||
if (assetId is null) |
} |
||||
|
|
||||
|
var assetId = orderLine.FindBookingAssetId(); |
||||
|
var assetCategoryId = orderLine.FindBookingAssetCategoryId(); |
||||
|
|
||||
|
if (assetId is not null) |
||||
|
{ |
||||
|
if (!await IsAssetInfoValidAsync(order, orderLine)) |
||||
{ |
{ |
||||
var assetCategoryId = orderLine.FindBookingAssetCategoryId(); |
return false; |
||||
if (assetCategoryId is null) |
|
||||
{ |
|
||||
continue; |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
// Todo: Invoke IAssetOccupancyAppService (in EasyAbp.EShop.Plugins.Booking, not EasyAbp.BookingService) to check the booking info.
|
var bookingDate = |
||||
|
Check.NotNull(orderLine.FindBookingDate(), BookingOrderProperties.OrderLineBookingDate)!.Value; |
||||
|
|
||||
|
var bookingStartingTime = Check.NotNull(orderLine.FindBookingStartingTime(), |
||||
|
BookingOrderProperties.OrderLineBookingStartingTime)!.Value; |
||||
|
|
||||
|
var bookingDuration = Check.NotNull(orderLine.FindBookingDuration(), |
||||
|
BookingOrderProperties.OrderLineBookingDuration)!.Value; |
||||
|
|
||||
|
models.Add(new OccupyAssetInfoModel( |
||||
|
assetId.Value, bookingDate, bookingStartingTime, bookingDuration)); |
||||
|
} |
||||
|
else if (assetCategoryId is not null) |
||||
|
{ |
||||
|
if (!await IsAssetCategoryInfoValidAsync(order, orderLine)) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
var bookingDate = |
||||
|
Check.NotNull(orderLine.FindBookingDate(), BookingOrderProperties.OrderLineBookingDate)!.Value; |
||||
|
|
||||
|
var bookingStartingTime = Check.NotNull(orderLine.FindBookingStartingTime(), |
||||
|
BookingOrderProperties.OrderLineBookingStartingTime)!.Value; |
||||
|
|
||||
|
var bookingDuration = Check.NotNull(orderLine.FindBookingDuration(), |
||||
|
BookingOrderProperties.OrderLineBookingDuration)!.Value; |
||||
|
|
||||
|
byCategoryModels.Add(new OccupyAssetByCategoryInfoModel( |
||||
|
assetCategoryId.Value, bookingDate, bookingStartingTime, bookingDuration)); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await _assetOccupancyAppService.CheckBulkCreateAsync(new BulkCreateAssetOccupancyDto |
||||
|
{ |
||||
|
OccupierUserId = Check.NotNull(context.User.FindUserId(), "CurrentUserId"), |
||||
|
Models = models, |
||||
|
ByCategoryModels = byCategoryModels |
||||
|
}); |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<bool> IsAssetInfoValidAsync(OrderDto order, OrderLineDto orderLine) |
||||
|
{ |
||||
|
var productAsset = (await _productAssetAppService.GetListAsync( |
||||
|
new GetProductAssetDto |
||||
|
{ |
||||
|
MaxResultCount = 1, |
||||
|
StoreId = order.StoreId, |
||||
|
ProductId = orderLine.ProductId, |
||||
|
ProductSkuId = orderLine.ProductSkuId, |
||||
|
AssetId = orderLine.FindBookingAssetId(), |
||||
|
PeriodSchemeId = orderLine.FindBookingPeriodSchemeId() |
||||
|
} |
||||
|
)).Items.FirstOrDefault(); |
||||
|
|
||||
|
return productAsset is not null; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<bool> IsAssetCategoryInfoValidAsync(OrderDto order, OrderLineDto orderLine) |
||||
|
{ |
||||
|
var productAssetCategory = (await _productAssetCategoryAppService.GetListAsync( |
||||
|
new GetProductAssetCategoryDto |
||||
|
{ |
||||
|
MaxResultCount = 1, |
||||
|
StoreId = order.StoreId, |
||||
|
ProductId = orderLine.ProductId, |
||||
|
ProductSkuId = orderLine.ProductSkuId, |
||||
|
AssetCategoryId = orderLine.FindBookingAssetCategoryId(), |
||||
|
PeriodSchemeId = orderLine.FindBookingPeriodSchemeId() |
||||
} |
} |
||||
|
)).Items.FirstOrDefault(); |
||||
|
|
||||
|
return productAssetCategory is not null; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<bool> IsPeriodInfoValidAsync(OrderLineDto orderLine) |
||||
|
{ |
||||
|
var periodSchemeId = orderLine.FindBookingPeriodSchemeId(); |
||||
|
var periodId = orderLine.FindBookingPeriodId(); |
||||
|
|
||||
|
if (periodSchemeId is null || periodId is null) |
||||
|
{ |
||||
|
return false; |
||||
} |
} |
||||
|
|
||||
|
var periodScheme = await _periodSchemeAppService.GetAsync(periodSchemeId.Value); |
||||
|
var period = periodScheme.Periods.Find(x => x.Id == periodId); |
||||
|
|
||||
|
return period is not null; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,18 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class GetProductAssetCategoryDto : PagedAndSortedResultRequestDto |
||||
|
{ |
||||
|
public Guid? StoreId { get; set; } |
||||
|
|
||||
|
public Guid? ProductId { get; set; } |
||||
|
|
||||
|
public Guid? ProductSkuId { get; set; } |
||||
|
|
||||
|
public Guid? AssetCategoryId { get; set; } |
||||
|
|
||||
|
public Guid? PeriodSchemeId { get; set; } |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Plugins.Booking.ProductAssets.Dtos; |
||||
|
|
||||
|
[Serializable] |
||||
|
public class GetProductAssetDto : PagedAndSortedResultRequestDto |
||||
|
{ |
||||
|
public Guid? StoreId { get; set; } |
||||
|
|
||||
|
public Guid? ProductId { get; set; } |
||||
|
|
||||
|
public Guid? ProductSkuId { get; set; } |
||||
|
|
||||
|
public Guid? AssetId { get; set; } |
||||
|
|
||||
|
public Guid? PeriodSchemeId { get; set; } |
||||
|
} |
||||
@ -1,67 +1,173 @@ |
|||||
using System; |
using System; |
||||
|
using System.Linq; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
using EasyAbp.BookingService.AssetCategories; |
||||
|
using EasyAbp.BookingService.PeriodSchemes; |
||||
using EasyAbp.EShop.Plugins.Booking.Permissions; |
using EasyAbp.EShop.Plugins.Booking.Permissions; |
||||
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; |
using EasyAbp.EShop.Plugins.Booking.ProductAssetCategories.Dtos; |
||||
|
using EasyAbp.EShop.Products.Products; |
||||
|
using EasyAbp.EShop.Stores.Stores; |
||||
|
using Volo.Abp; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
using Volo.Abp.Application.Services; |
|
||||
|
|
||||
namespace EasyAbp.EShop.Plugins.Booking.ProductAssetCategories |
namespace EasyAbp.EShop.Plugins.Booking.ProductAssetCategories |
||||
{ |
{ |
||||
public class ProductAssetCategoryAppService : CrudAppService<ProductAssetCategory, ProductAssetCategoryDto, Guid, PagedAndSortedResultRequestDto, CreateProductAssetCategoryDto, UpdateProductAssetCategoryDto>, |
public class ProductAssetCategoryAppService : MultiStoreCrudAppService<ProductAssetCategory, ProductAssetCategoryDto |
||||
|
, Guid, GetProductAssetCategoryDto, CreateProductAssetCategoryDto, UpdateProductAssetCategoryDto>, |
||||
IProductAssetCategoryAppService |
IProductAssetCategoryAppService |
||||
{ |
{ |
||||
|
protected override string CrossStorePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Manage; |
||||
protected override string GetPolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Default; |
protected override string GetPolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Default; |
||||
protected override string GetListPolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Default; |
protected override string GetListPolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Default; |
||||
protected override string CreatePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Create; |
protected override string CreatePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Create; |
||||
protected override string UpdatePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Update; |
protected override string UpdatePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Update; |
||||
protected override string DeletePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Delete; |
protected override string DeletePolicyName { get; set; } = BookingPermissions.ProductAssetCategory.Delete; |
||||
|
|
||||
|
private readonly IProductAppService _productAppService; |
||||
|
private readonly IPeriodSchemeAppService _periodSchemeAppService; |
||||
|
private readonly IAssetCategoryAppService _assetCategoryAppService; |
||||
private readonly IProductAssetCategoryRepository _repository; |
private readonly IProductAssetCategoryRepository _repository; |
||||
|
private readonly ProductAssetCategoryManager _productAssetCategoryManager; |
||||
|
|
||||
public ProductAssetCategoryAppService(IProductAssetCategoryRepository repository) : base(repository) |
public ProductAssetCategoryAppService( |
||||
|
IProductAppService productAppService, |
||||
|
IPeriodSchemeAppService periodSchemeAppService, |
||||
|
IAssetCategoryAppService assetCategoryAppService, |
||||
|
IProductAssetCategoryRepository repository, |
||||
|
ProductAssetCategoryManager productAssetCategoryManager) : base(repository) |
||||
{ |
{ |
||||
|
_productAppService = productAppService; |
||||
|
_periodSchemeAppService = periodSchemeAppService; |
||||
|
_assetCategoryAppService = assetCategoryAppService; |
||||
_repository = repository; |
_repository = repository; |
||||
|
_productAssetCategoryManager = productAssetCategoryManager; |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ProductAssetCategoryDto> CreatePeriodAsync(Guid productAssetCategoryId, CreateProductAssetCategoryPeriodDto input) |
protected override async Task<IQueryable<ProductAssetCategory>> CreateFilteredQueryAsync(GetProductAssetCategoryDto input) |
||||
{ |
{ |
||||
await CheckUpdatePolicyAsync(); |
return (await base.CreateFilteredQueryAsync(input)) |
||||
|
.WhereIf(input.StoreId.HasValue, x => x.StoreId == input.StoreId) |
||||
|
.WhereIf(input.ProductId.HasValue, x => x.ProductId == input.ProductId) |
||||
|
.WhereIf(input.ProductSkuId.HasValue, x => x.ProductSkuId == input.ProductSkuId) |
||||
|
.WhereIf(input.AssetCategoryId.HasValue, x => x.AssetCategoryId == input.AssetCategoryId) |
||||
|
.WhereIf(input.PeriodSchemeId.HasValue, x => x.PeriodSchemeId == input.PeriodSchemeId); |
||||
|
} |
||||
|
|
||||
|
public override async Task<PagedResultDto<ProductAssetCategoryDto>> GetListAsync( |
||||
|
GetProductAssetCategoryDto input) |
||||
|
{ |
||||
|
await CheckMultiStorePolicyAsync(input.StoreId, GetListPolicyName); |
||||
|
|
||||
var productAsset = await GetEntityByIdAsync(productAssetCategoryId); |
var query = await CreateFilteredQueryAsync(input); |
||||
|
|
||||
productAsset.AddPeriod(ObjectMapper.Map<CreateProductAssetCategoryPeriodDto, ProductAssetCategoryPeriod>(input)); |
var totalCount = await AsyncExecuter.CountAsync(query); |
||||
|
|
||||
await _repository.UpdateAsync(productAsset, true); |
query = ApplySorting(query, input); |
||||
|
query = ApplyPaging(query, input); |
||||
|
|
||||
return await MapToGetOutputDtoAsync(productAsset); |
var entities = await AsyncExecuter.ToListAsync(query); |
||||
|
var entityDtos = await MapToGetListOutputDtosAsync(entities); |
||||
|
|
||||
|
return new PagedResultDto<ProductAssetCategoryDto>( |
||||
|
totalCount, |
||||
|
entityDtos |
||||
|
); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ProductAssetCategoryDto> UpdatePeriodAsync(Guid productAssetCategoryId, Guid periodId, UpdateProductAssetCategoryPeriodDto input) |
public override async Task<ProductAssetCategoryDto> CreateAsync(CreateProductAssetCategoryDto input) |
||||
{ |
{ |
||||
await CheckUpdatePolicyAsync(); |
await CheckMultiStorePolicyAsync(input.StoreId, CreatePolicyName); |
||||
|
|
||||
var productAsset = await GetEntityByIdAsync(productAssetCategoryId); |
await EnsureProductSkuExistAsync(input.StoreId, input.ProductId, input.ProductSkuId); |
||||
|
await EnsureAssetCategoryExistAsync(input.AssetCategoryId); |
||||
|
await EnsurePeriodSchemeExistAsync(input.PeriodSchemeId); |
||||
|
|
||||
|
var entity = await MapToEntityAsync(input); |
||||
|
|
||||
|
TryToSetTenantId(entity); |
||||
|
|
||||
|
await Repository.InsertAsync(entity, autoSave: true); |
||||
|
|
||||
|
return await MapToGetOutputDtoAsync(entity); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task EnsureProductSkuExistAsync(Guid storeId, Guid productId, Guid productSkuId) |
||||
|
{ |
||||
|
var product = await _productAppService.GetAsync(productId); |
||||
|
|
||||
|
if (product.StoreId != storeId) |
||||
|
{ |
||||
|
throw (new BusinessException(BookingErrorCodes.WrongStoreIdForProduct)) |
||||
|
.WithData(nameof(storeId), storeId) |
||||
|
.WithData(nameof(productId), productId); |
||||
|
} |
||||
|
|
||||
|
product.GetSkuById(productSkuId); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task EnsureAssetCategoryExistAsync(Guid assetCategoryId) |
||||
|
{ |
||||
|
await _assetCategoryAppService.GetAsync(assetCategoryId); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task EnsurePeriodSchemeExistAsync(Guid periodSchemeId) |
||||
|
{ |
||||
|
await _periodSchemeAppService.GetAsync(periodSchemeId); |
||||
|
} |
||||
|
|
||||
|
protected override async Task<ProductAssetCategory> MapToEntityAsync(CreateProductAssetCategoryDto input) |
||||
|
{ |
||||
|
return await _productAssetCategoryManager.CreateAsync(input.StoreId, input.ProductId, input.ProductSkuId, |
||||
|
input.AssetCategoryId, input.PeriodSchemeId, input.FromTime, input.ToTime, input.Price); |
||||
|
} |
||||
|
|
||||
|
protected override async Task MapToEntityAsync(UpdateProductAssetCategoryDto input, ProductAssetCategory entity) |
||||
|
{ |
||||
|
await _productAssetCategoryManager.UpdateAsync(entity, input.FromTime, input.ToTime, input.Price); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ProductAssetCategoryDto> CreatePeriodAsync(Guid productAssetCategoryId, |
||||
|
CreateProductAssetCategoryPeriodDto input) |
||||
|
{ |
||||
|
var productAssetCategory = await GetEntityByIdAsync(productAssetCategoryId); |
||||
|
|
||||
|
await CheckMultiStorePolicyAsync(productAssetCategory.StoreId, UpdatePolicyName); |
||||
|
|
||||
|
productAssetCategory.AddPeriod( |
||||
|
ObjectMapper.Map<CreateProductAssetCategoryPeriodDto, ProductAssetCategoryPeriod>(input)); |
||||
|
|
||||
|
await _repository.UpdateAsync(productAssetCategory, true); |
||||
|
|
||||
|
return await MapToGetOutputDtoAsync(productAssetCategory); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ProductAssetCategoryDto> UpdatePeriodAsync(Guid productAssetCategoryId, Guid periodId, |
||||
|
UpdateProductAssetCategoryPeriodDto input) |
||||
|
{ |
||||
|
var productAssetCategory = await GetEntityByIdAsync(productAssetCategoryId); |
||||
|
|
||||
|
await CheckMultiStorePolicyAsync(productAssetCategory.StoreId, UpdatePolicyName); |
||||
|
|
||||
|
var productAssetCategoryPeriod = productAssetCategory.GetPeriod(periodId); |
||||
|
|
||||
var productAssetCategoryPeriod = productAsset.GetPeriod(periodId); |
|
||||
|
|
||||
ObjectMapper.Map(input, productAssetCategoryPeriod); |
ObjectMapper.Map(input, productAssetCategoryPeriod); |
||||
|
|
||||
await _repository.UpdateAsync(productAsset, true); |
await _repository.UpdateAsync(productAssetCategory, true); |
||||
|
|
||||
return await MapToGetOutputDtoAsync(productAsset); |
return await MapToGetOutputDtoAsync(productAssetCategory); |
||||
} |
} |
||||
|
|
||||
public virtual async Task<ProductAssetCategoryDto> DeletePeriodAsync(Guid productAssetCategoryId, Guid periodId) |
public virtual async Task<ProductAssetCategoryDto> DeletePeriodAsync(Guid productAssetCategoryId, Guid periodId) |
||||
{ |
{ |
||||
await CheckUpdatePolicyAsync(); |
var productAssetCategory = await GetEntityByIdAsync(productAssetCategoryId); |
||||
|
|
||||
var productAsset = await GetEntityByIdAsync(productAssetCategoryId); |
await CheckMultiStorePolicyAsync(productAssetCategory.StoreId, UpdatePolicyName); |
||||
|
|
||||
productAsset.RemovePeriod(periodId); |
productAssetCategory.RemovePeriod(periodId); |
||||
|
|
||||
await _repository.UpdateAsync(productAsset, true); |
await _repository.UpdateAsync(productAssetCategory, true); |
||||
|
|
||||
return await MapToGetOutputDtoAsync(productAsset); |
return await MapToGetOutputDtoAsync(productAssetCategory); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,9 +1,15 @@ |
|||||
using System; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
using Volo.Abp.Domain.Repositories; |
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
namespace EasyAbp.EShop.Plugins.Booking.ProductAssetCategories |
namespace EasyAbp.EShop.Plugins.Booking.ProductAssetCategories |
||||
{ |
{ |
||||
public interface IProductAssetCategoryRepository : IRepository<ProductAssetCategory, Guid> |
public interface IProductAssetCategoryRepository : IRepository<ProductAssetCategory, Guid> |
||||
{ |
{ |
||||
|
Task<ProductAssetCategory> FindEffectiveAsync(DateTime currentTime, Guid storeId, Guid productId, |
||||
|
Guid productSkuId, Guid assetCategoryId, Guid periodSchemeId); |
||||
|
|
||||
|
Task<bool> ExistConflictAsync(Guid id, Guid storeId, Guid productId, Guid productSkuId, Guid assetCategoryId, |
||||
|
Guid periodSchemeId, DateTime fromTime); |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Plugins.Booking.ProductAssetCategories; |
||||
|
|
||||
|
public class ProductAssetCategoryManager : DomainService |
||||
|
{ |
||||
|
private readonly IProductAssetCategoryRepository _repository; |
||||
|
|
||||
|
public ProductAssetCategoryManager(IProductAssetCategoryRepository repository) |
||||
|
{ |
||||
|
_repository = repository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ProductAssetCategory> CreateAsync(Guid storeId, Guid productId, Guid productSkuId, Guid assetCategoryId, |
||||
|
Guid periodSchemeId, DateTime fromTime, DateTime? toTime, decimal? price) |
||||
|
{ |
||||
|
var id = GuidGenerator.Create(); |
||||
|
|
||||
|
if (await _repository.ExistConflictAsync( |
||||
|
id, storeId, productId, productSkuId, assetCategoryId, periodSchemeId, fromTime)) |
||||
|
{ |
||||
|
throw new BusinessException(BookingErrorCodes.ConflictingProductAssetCategory); |
||||
|
} |
||||
|
|
||||
|
return new ProductAssetCategory(GuidGenerator.Create(), CurrentTenant.Id, storeId, productId, productSkuId, assetCategoryId, |
||||
|
periodSchemeId, fromTime, toTime, price, new List<ProductAssetCategoryPeriod>()); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task UpdateAsync(ProductAssetCategory entity, DateTime fromTime, DateTime? toTime, decimal? price) |
||||
|
{ |
||||
|
if (await _repository.ExistConflictAsync(entity.Id, entity.StoreId, entity.ProductId, entity.ProductSkuId, |
||||
|
entity.AssetCategoryId, entity.PeriodSchemeId, fromTime)) |
||||
|
{ |
||||
|
throw new BusinessException(BookingErrorCodes.ConflictingProductAssetCategory); |
||||
|
} |
||||
|
|
||||
|
entity.Update(fromTime, toTime, price); |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,15 @@ |
|||||
using System; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
using Volo.Abp.Domain.Repositories; |
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
namespace EasyAbp.EShop.Plugins.Booking.ProductAssets |
namespace EasyAbp.EShop.Plugins.Booking.ProductAssets |
||||
{ |
{ |
||||
public interface IProductAssetRepository : IRepository<ProductAsset, Guid> |
public interface IProductAssetRepository : IRepository<ProductAsset, Guid> |
||||
{ |
{ |
||||
|
Task<ProductAsset> FindEffectiveAsync(DateTime currentTime, Guid storeId, Guid productId, Guid productSkuId, |
||||
|
Guid assetId, Guid periodSchemeId); |
||||
|
|
||||
|
Task<bool> ExistConflictAsync(Guid id, Guid storeId, Guid productId, Guid productSkuId, Guid assetId, |
||||
|
Guid periodSchemeId, DateTime fromTime); |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Plugins.Booking.ProductAssets; |
||||
|
|
||||
|
public class ProductAssetManager : DomainService |
||||
|
{ |
||||
|
private readonly IProductAssetRepository _repository; |
||||
|
|
||||
|
public ProductAssetManager(IProductAssetRepository repository) |
||||
|
{ |
||||
|
_repository = repository; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<ProductAsset> CreateAsync(Guid storeId, Guid productId, Guid productSkuId, Guid assetId, |
||||
|
Guid periodSchemeId, DateTime fromTime, DateTime? toTime, decimal? price) |
||||
|
{ |
||||
|
var id = GuidGenerator.Create(); |
||||
|
|
||||
|
if (await _repository.ExistConflictAsync( |
||||
|
id, storeId, productId, productSkuId, assetId, periodSchemeId, fromTime)) |
||||
|
{ |
||||
|
throw new BusinessException(BookingErrorCodes.ConflictingProductAsset); |
||||
|
} |
||||
|
|
||||
|
return new ProductAsset(GuidGenerator.Create(), CurrentTenant.Id, storeId, productId, productSkuId, assetId, |
||||
|
periodSchemeId, fromTime, toTime, price, new List<ProductAssetPeriod>()); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task UpdateAsync(ProductAsset entity, DateTime fromTime, DateTime? toTime, decimal? price) |
||||
|
{ |
||||
|
if (await _repository.ExistConflictAsync(entity.Id, entity.StoreId, entity.ProductId, entity.ProductSkuId, |
||||
|
entity.AssetId, entity.PeriodSchemeId, fromTime)) |
||||
|
{ |
||||
|
throw new BusinessException(BookingErrorCodes.ConflictingProductAsset); |
||||
|
} |
||||
|
|
||||
|
entity.Update(fromTime, toTime, price); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using EasyAbp.Abp.TagHelperPlus.EasySelector; |
||||
|
using EasyAbp.EShop.Stores; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssetCategories.ProductAssetCategory.ViewModels |
||||
|
{ |
||||
|
public class ProductAssetCategoryListFilterViewModel |
||||
|
{ |
||||
|
[EasySelector( |
||||
|
getListedDataSourceUrl: StoresConsts.GetStoreListedDataSourceUrl + "?onlyManageable=true", |
||||
|
getSingleDataSourceUrl: StoresConsts.GetStoreSingleDataSourceUrl, |
||||
|
keyPropertyName: "id", |
||||
|
textPropertyName: "name", |
||||
|
runScriptOnWindowLoad: true)] |
||||
|
[Display(Name = "ProductAssetCategoryStoreId")] |
||||
|
public Guid? StoreId { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using EasyAbp.Abp.TagHelperPlus.EasySelector; |
||||
|
using EasyAbp.EShop.Products; |
||||
|
using EasyAbp.EShop.Stores; |
||||
|
|
||||
|
namespace EasyAbp.EShop.Plugins.Booking.Web.Pages.EShop.Plugins.Booking.ProductAssets.ProductAsset.ViewModels |
||||
|
{ |
||||
|
public class ProductAssetListFilterViewModel |
||||
|
{ |
||||
|
[EasySelector( |
||||
|
getListedDataSourceUrl: StoresConsts.GetStoreListedDataSourceUrl + "?onlyManageable=true", |
||||
|
getSingleDataSourceUrl: StoresConsts.GetStoreSingleDataSourceUrl, |
||||
|
keyPropertyName: "id", |
||||
|
textPropertyName: "name", |
||||
|
runScriptOnWindowLoad: true)] |
||||
|
[Display(Name = "ProductAssetStoreId")] |
||||
|
public Guid? StoreId { get; set; } |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,38 @@ |
|||||
|
using System; |
||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace EShopSample.Migrations |
||||
|
{ |
||||
|
public partial class AddedStoreIdInProductAssetAndProductAssetCategory : Migration |
||||
|
{ |
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.AddColumn<Guid>( |
||||
|
name: "StoreId", |
||||
|
table: "EasyAbpEShopPluginsBookingProductAssets", |
||||
|
type: "uniqueidentifier", |
||||
|
nullable: false, |
||||
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); |
||||
|
|
||||
|
migrationBuilder.AddColumn<Guid>( |
||||
|
name: "StoreId", |
||||
|
table: "EasyAbpEShopPluginsBookingProductAssetCategories", |
||||
|
type: "uniqueidentifier", |
||||
|
nullable: false, |
||||
|
defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); |
||||
|
} |
||||
|
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "StoreId", |
||||
|
table: "EasyAbpEShopPluginsBookingProductAssets"); |
||||
|
|
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "StoreId", |
||||
|
table: "EasyAbpEShopPluginsBookingProductAssetCategories"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue