From 5d2df984fa99dd88c6b9e465570cc5b7c8edeadc Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sun, 12 Jun 2022 03:45:47 +0800 Subject: [PATCH] Use IProductAppService to change inventories --- .../Dtos/ProductInventoryDto.cs | 17 --- .../Dtos/UpdateProductInventoryDto.cs | 18 --- .../IProductInventoryAppService.cs | 15 --- .../Dtos/ChangeProductInventoryDto.cs | 13 +++ .../Dtos/ChangeProductInventoryResultDto.cs | 14 +++ .../Products/Products/IProductAppService.cs | 11 +- .../ProductInventoryAppService.cs | 104 ------------------ .../Products/Products/ProductAppService.cs | 23 ++++ .../ProductsApplicationAutoMapperProfile.cs | 3 - .../ProductInventoryController.cs | 33 ------ .../Products/Products/ProductController.cs | 8 ++ .../ProductSku/ChangeInventoryModal.cshtml.cs | 21 ++-- .../Products/ProductSku/CreateModal.cshtml.cs | 22 ++-- .../ProductInventoryAppServiceTests.cs | 26 ----- 14 files changed, 82 insertions(+), 246 deletions(-) delete mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/ProductInventoryDto.cs delete mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/UpdateProductInventoryDto.cs delete mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/IProductInventoryAppService.cs create mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryDto.cs create mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryResultDto.cs delete mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductInventories/ProductInventoryAppService.cs delete mode 100644 modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/ProductInventories/ProductInventoryController.cs delete mode 100644 modules/EasyAbp.EShop.Products/test/EasyAbp.EShop.Products.Application.Tests/ProductInventories/ProductInventoryAppServiceTests.cs diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/ProductInventoryDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/ProductInventoryDto.cs deleted file mode 100644 index 4dc5ca9d..00000000 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/ProductInventoryDto.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using Volo.Abp.Application.Dtos; - -namespace EasyAbp.EShop.Products.ProductInventories.Dtos -{ - [Serializable] - public class ProductInventoryDto : ExtensibleFullAuditedEntityDto - { - public Guid ProductId { get; set; } - - public Guid ProductSkuId { get; set; } - - public int Inventory { get; set; } - - public long Sold { get; set; } - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/UpdateProductInventoryDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/UpdateProductInventoryDto.cs deleted file mode 100644 index aa56c690..00000000 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/Dtos/UpdateProductInventoryDto.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Volo.Abp.ObjectExtending; - -namespace EasyAbp.EShop.Products.ProductInventories.Dtos -{ - [Serializable] - public class UpdateProductInventoryDto : ExtensibleObject - { - public Guid ProductId { get; set; } - - public Guid ProductSkuId { get; set; } - - /// - /// Reduce inventory if the value is less than 0 - /// - public int ChangedInventory { get; set; } - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/IProductInventoryAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/IProductInventoryAppService.cs deleted file mode 100644 index 5da554be..00000000 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/ProductInventories/IProductInventoryAppService.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Threading.Tasks; -using EasyAbp.EShop.Products.ProductInventories.Dtos; -using Volo.Abp.Application.Dtos; -using Volo.Abp.Application.Services; - -namespace EasyAbp.EShop.Products.ProductInventories -{ - public interface IProductInventoryAppService : IApplicationService - { - Task GetAsync(Guid productId, Guid productSkuId); - - Task UpdateAsync(UpdateProductInventoryDto input); - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryDto.cs new file mode 100644 index 00000000..52c139a4 --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryDto.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp.ObjectExtending; + +namespace EasyAbp.EShop.Products.Products.Dtos; + +[Serializable] +public class ChangeProductInventoryDto : ExtensibleObject +{ + /// + /// Reduce inventory if the value is less than 0 + /// + public int ChangedInventory { get; set; } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryResultDto.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryResultDto.cs new file mode 100644 index 00000000..77d93312 --- /dev/null +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/Dtos/ChangeProductInventoryResultDto.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.ObjectExtending; + +namespace EasyAbp.EShop.Products.Products.Dtos; + +[Serializable] +public class ChangeProductInventoryResultDto : ExtensibleObject +{ + public bool Changed { get; set; } + + public int ChangedInventory { get; set; } + + public int CurrentInventory { get; set; } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs index 09790399..e0253224 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application.Contracts/EasyAbp/EShop/Products/Products/IProductAppService.cs @@ -7,9 +7,9 @@ using Volo.Abp.Application.Services; namespace EasyAbp.EShop.Products.Products { public interface IProductAppService : - ICrudAppService< - ProductDto, - Guid, + ICrudAppService< + ProductDto, + Guid, GetProductListInput, CreateUpdateProductDto, CreateUpdateProductDto> @@ -19,9 +19,12 @@ namespace EasyAbp.EShop.Products.Products Task UpdateSkuAsync(Guid productId, Guid productSkuId, UpdateProductSkuDto input); Task DeleteSkuAsync(Guid productId, Guid productSkuId); - + Task GetByUniqueNameAsync(Guid storeId, string uniqueName); Task> GetProductGroupListAsync(); + + Task ChangeInventoryAsync(Guid id, Guid productSkuId, + ChangeProductInventoryDto input); } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductInventories/ProductInventoryAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductInventories/ProductInventoryAppService.cs deleted file mode 100644 index 9b3307a0..00000000 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductInventories/ProductInventoryAppService.cs +++ /dev/null @@ -1,104 +0,0 @@ -using EasyAbp.EShop.Products.Permissions; -using EasyAbp.EShop.Products.ProductInventories.Dtos; -using EasyAbp.EShop.Products.Products; -using EasyAbp.EShop.Stores.Authorization; -using Microsoft.AspNetCore.Authorization; -using System; -using System.Threading.Tasks; -using Volo.Abp.Application.Services; -using Volo.Abp.Domain.Entities; - -namespace EasyAbp.EShop.Products.ProductInventories -{ - public class ProductInventoryAppService : ApplicationService, IProductInventoryAppService - { - private readonly IProductRepository _productRepository; - private readonly IProductInventoryRepository _repository; - private readonly DefaultProductInventoryProvider _defaultProductInventoryProvider; - - public ProductInventoryAppService( - IProductRepository productRepository, - IProductInventoryRepository repository, - DefaultProductInventoryProvider defaultProductInventoryProvider) - { - _productRepository = productRepository; - _repository = repository; - _defaultProductInventoryProvider = defaultProductInventoryProvider; - } - - [Authorize(ProductsPermissions.ProductInventory.Default)] - public virtual async Task GetAsync(Guid productId, Guid productSkuId) - { - var productInventory = await _repository.FindAsync(x => x.ProductSkuId == productSkuId); - - if (productInventory == null) - { - var product = await _productRepository.GetAsync(productId); - - if (!product.ProductSkus.Exists(x => x.Id == productSkuId)) - { - throw new EntityNotFoundException(typeof(ProductSku), productSkuId); - } - - productInventory = new ProductInventory(GuidGenerator.Create(), CurrentTenant.Id, productId, - productSkuId, 0, 0); - - await _repository.InsertAsync(productInventory, true); - } - - return ObjectMapper.Map(productInventory); - } - - public virtual async Task UpdateAsync(UpdateProductInventoryDto input) - { - var product = await _productRepository.GetAsync(input.ProductId); - - if (!product.ProductSkus.Exists(x => x.Id == input.ProductSkuId)) - { - throw new EntityNotFoundException(typeof(ProductSku), input.ProductSkuId); - } - - await AuthorizationService.CheckMultiStorePolicyAsync(product.StoreId, - ProductsPermissions.ProductInventory.Update, ProductsPermissions.ProductInventory.CrossStore); - - var productInventory = await _repository.FindAsync(x => x.ProductSkuId == input.ProductSkuId); - - if (productInventory == null) - { - productInventory = - new ProductInventory(GuidGenerator.Create(), CurrentTenant.Id, input.ProductId, input.ProductSkuId, - 0, 0); - - await _repository.InsertAsync(productInventory, true); - } - - await ChangeInventoryAsync(product, productInventory, input.ChangedInventory); - - return ObjectMapper.Map(productInventory); - } - - protected virtual async Task ChangeInventoryAsync(Product product, ProductInventory productInventory, - int changedInventory) - { - var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, - productInventory.ProductSkuId); - - if (changedInventory >= 0) - { - if (!await _defaultProductInventoryProvider.TryIncreaseInventoryAsync(model, changedInventory, false)) - { - throw new InventoryChangeFailedException(productInventory.ProductId, productInventory.ProductSkuId, - productInventory.Inventory, changedInventory); - } - } - else - { - if (!await _defaultProductInventoryProvider.TryReduceInventoryAsync(model, -changedInventory, false)) - { - throw new InventoryChangeFailedException(productInventory.ProductId, productInventory.ProductSkuId, - productInventory.Inventory, changedInventory); - } - } - } - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs index 5f51075e..0f1f3bc6 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs @@ -442,6 +442,29 @@ namespace EasyAbp.EShop.Products.Products ).ToList())); } + public virtual async Task ChangeInventoryAsync(Guid id, Guid productSkuId, + ChangeProductInventoryDto input) + { + var product = await GetEntityByIdAsync(id); + var sku = product.ProductSkus.Single(x => x.Id == productSkuId); + + var changed = input.ChangedInventory switch + { + > 0 => await _productManager.TryIncreaseInventoryAsync(product, sku, input.ChangedInventory, false), + < 0 => await _productManager.TryReduceInventoryAsync(product, sku, -1 * input.ChangedInventory, false), + _ => false + }; + + var model = await _productManager.GetInventoryDataAsync(product, sku); + + return new ChangeProductInventoryResultDto + { + Changed = changed, + ChangedInventory = input.ChangedInventory, + CurrentInventory = model.Inventory + }; + } + protected override ProductDto MapToGetOutputDto(Product entity) { var productDto = base.MapToGetOutputDto(entity); diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs index 43c98589..bfefd578 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductsApplicationAutoMapperProfile.cs @@ -9,8 +9,6 @@ using EasyAbp.EShop.Products.ProductDetails; using EasyAbp.EShop.Products.ProductDetails.Dtos; using EasyAbp.EShop.Products.ProductHistories; using EasyAbp.EShop.Products.ProductHistories.Dtos; -using EasyAbp.EShop.Products.ProductInventories; -using EasyAbp.EShop.Products.ProductInventories.Dtos; using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products.Dtos; using System.Linq; @@ -65,7 +63,6 @@ namespace EasyAbp.EShop.Products CreateMap(); CreateMap(); CreateMap(); - CreateMap(); CreateMap(); CreateMap(MemberList.Destination); } diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/ProductInventories/ProductInventoryController.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/ProductInventories/ProductInventoryController.cs deleted file mode 100644 index 375e5b48..00000000 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/ProductInventories/ProductInventoryController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Threading.Tasks; -using EasyAbp.EShop.Products.ProductInventories.Dtos; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp; -using Volo.Abp.Application.Dtos; - -namespace EasyAbp.EShop.Products.ProductInventories -{ - [RemoteService(Name = EShopProductsRemoteServiceConsts.RemoteServiceName)] - [Route("/api/e-shop/products/product-inventory")] - public class ProductInventoryController : ProductsController, IProductInventoryAppService - { - private readonly IProductInventoryAppService _service; - - public ProductInventoryController(IProductInventoryAppService service) - { - _service = service; - } - - [HttpGet] - public Task GetAsync(Guid productId, Guid productSkuId) - { - return _service.GetAsync(productId, productSkuId); - } - - [HttpPut] - public Task UpdateAsync(UpdateProductInventoryDto input) - { - return _service.UpdateAsync(input); - } - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Products/ProductController.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Products/ProductController.cs index 58bb6e85..09565735 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Products/ProductController.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.HttpApi/EasyAbp/EShop/Products/Products/ProductController.cs @@ -93,5 +93,13 @@ namespace EasyAbp.EShop.Products.Products { return _service.GetProductGroupListAsync(); } + + [HttpPost] + [Route("{id}/sku/{productSkuId}/change-inventory")] + public Task ChangeInventoryAsync(Guid id, Guid productSkuId, + ChangeProductInventoryDto input) + { + return _service.ChangeInventoryAsync(id, productSkuId, input); + } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/ChangeInventoryModal.cshtml.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/ChangeInventoryModal.cshtml.cs index 7d8d7208..1733ec0b 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/ChangeInventoryModal.cshtml.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/ChangeInventoryModal.cshtml.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -using EasyAbp.EShop.Products.ProductInventories; -using EasyAbp.EShop.Products.ProductInventories.Dtos; +using EasyAbp.EShop.Products.Products; +using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku.ViewModels; using Microsoft.AspNetCore.Mvc; @@ -12,7 +12,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku [HiddenInput] [BindProperty(SupportsGet = true)] public Guid ProductId { get; set; } - + [HiddenInput] [BindProperty(SupportsGet = true)] public Guid ProductSkuId { get; set; } @@ -20,17 +20,18 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku [BindProperty] public ChangeProductInventoryViewModel ViewModel { get; set; } - private readonly IProductInventoryAppService _service; + private readonly IProductAppService _service; - public ChangeInventoryModal(IProductInventoryAppService service) + public ChangeInventoryModal(IProductAppService service) { _service = service; } public virtual async Task OnGetAsync() { - var dto = await _service.GetAsync(ProductId, ProductSkuId); - + var product = await _service.GetAsync(ProductId); + product.GetSkuById(ProductSkuId); // ensure the specified sku exists. + ViewModel = new ChangeProductInventoryViewModel { ChangedInventory = 0, @@ -40,15 +41,13 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku public virtual async Task OnPostAsync() { - await _service.UpdateAsync(new UpdateProductInventoryDto + await _service.ChangeInventoryAsync(ProductId, ProductSkuId, new ChangeProductInventoryDto { - ProductId = ProductId, - ProductSkuId = ProductSkuId, ChangedInventory = ViewModel.ProductInventoryChangeType == InventoryChangeType.IncreaseInventory ? ViewModel.ChangedInventory : -ViewModel.ChangedInventory }); - + return NoContent(); } } diff --git a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/CreateModal.cshtml.cs b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/CreateModal.cshtml.cs index 667e0cb2..234bd13b 100644 --- a/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/CreateModal.cshtml.cs +++ b/modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Web/Pages/EShop/Products/Products/ProductSku/CreateModal.cshtml.cs @@ -4,8 +4,6 @@ using System.Linq; using System.Threading.Tasks; using EasyAbp.EShop.Products.ProductDetails; using EasyAbp.EShop.Products.ProductDetails.Dtos; -using EasyAbp.EShop.Products.ProductInventories; -using EasyAbp.EShop.Products.ProductInventories.Dtos; using EasyAbp.EShop.Products.Products; using EasyAbp.EShop.Products.Products.Dtos; using EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku.ViewModels; @@ -19,25 +17,22 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku [HiddenInput] [BindProperty(SupportsGet = true)] public Guid ProductId { get; set; } - + [BindProperty] public CreateProductSkuViewModel ProductSku { get; set; } = new CreateProductSkuViewModel(); - + [BindProperty] public Dictionary SelectedAttributeOptionIdDict { get; set; } - + public Dictionary> Attributes { get; set; } - private readonly IProductInventoryAppService _productInventoryAppService; private readonly IProductDetailAppService _productDetailAppService; private readonly IProductAppService _productAppService; public CreateModalModel( - IProductInventoryAppService productInventoryAppService, IProductDetailAppService productDetailAppService, IProductAppService productAppService) { - _productInventoryAppService = productInventoryAppService; _productDetailAppService = productDetailAppService; _productAppService = productAppService; } @@ -47,7 +42,7 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku var product = await _productAppService.GetAsync(ProductId); Attributes = new Dictionary>(); - + foreach (var attribute in product.ProductAttributes.ToList()) { Attributes.Add(attribute.DisplayName, @@ -55,13 +50,12 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku .Select(dto => new SelectListItem(dto.DisplayName, dto.Id.ToString())).ToList()); } } - + public virtual async Task OnPostAsync() { var createDto = ObjectMapper.Map(ProductSku); createDto.AttributeOptionIds = SelectedAttributeOptionIdDict.Values.ToList(); - if (ProductSku.ProductDetail.HasContent()) { var detail = await _productDetailAppService.CreateAsync( @@ -70,15 +64,13 @@ namespace EasyAbp.EShop.Products.Web.Pages.EShop.Products.Products.ProductSku createDto.ProductDetailId = detail.Id; } - + var product = await _productAppService.CreateSkuAsync(ProductId, createDto); var productSku = product.ProductSkus .Single(x => !x.AttributeOptionIds.Except(createDto.AttributeOptionIds).Any()); - await _productInventoryAppService.UpdateAsync(new UpdateProductInventoryDto + await _productAppService.ChangeInventoryAsync(product.Id, productSku.Id, new ChangeProductInventoryDto { - ProductId = product.Id, - ProductSkuId = productSku.Id, ChangedInventory = ProductSku.Inventory }); diff --git a/modules/EasyAbp.EShop.Products/test/EasyAbp.EShop.Products.Application.Tests/ProductInventories/ProductInventoryAppServiceTests.cs b/modules/EasyAbp.EShop.Products/test/EasyAbp.EShop.Products.Application.Tests/ProductInventories/ProductInventoryAppServiceTests.cs deleted file mode 100644 index e6e069de..00000000 --- a/modules/EasyAbp.EShop.Products/test/EasyAbp.EShop.Products.Application.Tests/ProductInventories/ProductInventoryAppServiceTests.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Shouldly; -using System.Threading.Tasks; -using Xunit; - -namespace EasyAbp.EShop.Products.ProductInventories -{ - public class ProductInventoryAppServiceTests : ProductsApplicationTestBase - { - private readonly IProductInventoryAppService _productInventoryAppService; - - public ProductInventoryAppServiceTests() - { - _productInventoryAppService = GetRequiredService(); - } - - [Fact] - public async Task Test1() - { - // Arrange - - // Act - - // Assert - } - } -}