From 530f82e0615542ab86bea22dd7d109037eb1d2c7 Mon Sep 17 00:00:00 2001 From: RayMMond Date: Thu, 13 Aug 2020 08:38:44 +0800 Subject: [PATCH] make StoreOwner has its own application service and management pages --- .../EShop/Orders/Orders/IOrderManager.cs | 1 - .../Payments/Payments/PaymentAppService.cs | 41 ++------- .../Payments/Refunds/RefundAppService.cs | 25 +----- ...asicStorePermissionAuthorizationHandler.cs | 8 +- .../Stores/StoreOwners/Dtos/StoreOwnerDto.cs | 5 +- .../StoreOwners/IStoreOwnerAppService.cs | 3 +- .../StoreOwnerDuplicatedException.cs | 13 +++ .../Stores/Dtos/CreateUpdateStoreDto.cs | 5 +- .../EShop/Stores/Stores/Dtos/StoreDto.cs | 2 + .../StoreOwners/StoreOwnerAppService.cs | 32 +++---- .../EShop/Stores/Stores/StoreAppService.cs | 43 +++------ .../StoresApplicationAutoMapperProfile.cs | 9 +- .../EShop/Stores/Localization/Stores/cs.json | 7 +- .../EShop/Stores/Localization/Stores/en.json | 7 +- .../EShop/Stores/Localization/Stores/pl.json | 7 +- .../Stores/Localization/Stores/pt-BR.json | 7 +- .../EShop/Stores/Localization/Stores/sl.json | 7 +- .../EShop/Stores/Localization/Stores/tr.json | 7 +- .../EShop/Stores/Localization/Stores/vi.json | 7 +- .../Stores/Localization/Stores/zh-Hans.json | 7 +- .../Stores/Localization/Stores/zh-Hant.json | 7 +- .../Stores/StoreOwners/IStoreOwnerStore.cs | 10 +++ .../EasyAbp.EShop.Stores.Domain.csproj | 1 + .../StoreOwners/IStoreOwnerRepository.cs | 4 +- .../Stores/StoreOwners/StoreOwnerCacheItem.cs | 24 +++++ .../Stores/StoreOwners/StoreOwnerStore.cs | 81 +++++++++++++++++ .../EShop/Stores/Stores/IStoreManager.cs | 14 --- .../EShop/Stores/Stores/StoreManager.cs | 58 ------------- .../StoresDbContextModelCreatingExtensions.cs | 3 + .../StoreOwners/StoreOwnerRepository.cs | 15 +++- .../StoreOwners/StoreOwnerController.cs | 30 +++++-- .../EasyAbp.EShop.Stores.Web.csproj | 34 ++++++++ .../Menus/StoresMenuContributor.cs | 7 ++ .../Menus/StoresMenus.cs | 2 + .../StoreOwners/StoreOwner/CreateModal.cshtml | 19 ++++ .../StoreOwner/CreateModal.cshtml.cs | 46 ++++++++++ .../StoreOwners/StoreOwner/EditModal.cshtml | 20 +++++ .../StoreOwner/EditModal.cshtml.cs | 53 +++++++++++ .../StoreOwners/StoreOwner/Index.cshtml | 61 +++++++++++++ .../StoreOwners/StoreOwner/Index.cshtml.cs | 21 +++++ .../Stores/StoreOwners/StoreOwner/Index.css | 0 .../Stores/StoreOwners/StoreOwner/Index.js | 87 +++++++++++++++++++ .../ViewModels/CreateStoreOwnerViewModel.cs | 17 ++++ .../Stores/Stores/Store/CreateModal.cshtml.cs | 2 +- .../Stores/Stores/Store/EditModal.cshtml.cs | 21 +---- .../EShop/Stores/Stores/Store/Index.cshtml | 4 +- .../ViewModels/CreateEditStoreViewModel.cs | 5 -- .../StoresWebAutoMapperProfile.cs | 12 ++- 48 files changed, 662 insertions(+), 239 deletions(-) create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerDuplicatedException.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerStore.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerCacheItem.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerStore.cs delete mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreManager.cs delete mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreManager.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml.cs create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.css create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.js create mode 100644 modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/ViewModels/CreateStoreOwnerViewModel.cs diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/IOrderManager.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/IOrderManager.cs index 00bd58ef..ff6afc69 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/IOrderManager.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/IOrderManager.cs @@ -7,7 +7,6 @@ namespace EasyAbp.EShop.Orders.Orders public interface IOrderManager : IDomainService { Task DiscountAsync(Order order, Dictionary inputExtraProperties); - Task DiscountAsync(Order order); Task CompleteAsync(Order order); } diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs index 3c98ccc5..c25a47fd 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs @@ -26,7 +26,8 @@ namespace EasyAbp.EShop.Payments.Payments private readonly IPayableChecker _payableChecker; private readonly IDistributedEventBus _distributedEventBus; private readonly IOrderAppService _orderAppService; - + private readonly IPaymentRepository _repository; + public PaymentAppService( IPayableChecker payableChecker, IDistributedEventBus distributedEventBus, @@ -36,33 +37,21 @@ namespace EasyAbp.EShop.Payments.Payments _payableChecker = payableChecker; _distributedEventBus = distributedEventBus; _orderAppService = orderAppService; + _repository = repository; } public override async Task GetAsync(Guid id) { var payment = await base.GetAsync(id); - await AuthorizationService.CheckAsync(GetPolicyName); - if (payment.UserId != CurrentUser.GetId()) { - if (payment.StoreId.HasValue) - { - if (await AuthorizationService.IsStoreOwnerGrantedAsync(payment.StoreId.Value, - PaymentsPermissions.Payments.Manage)) - { - return payment; - } - - await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.CrossStore); - } - await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.Manage); } return payment; } - + protected override IQueryable CreateFilteredQuery(GetPaymentListDto input) { var query = base.CreateFilteredQuery(input); @@ -80,40 +69,24 @@ namespace EasyAbp.EShop.Payments.Payments if (input.UserId != CurrentUser.GetId()) { await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.Manage); - - if (input.StoreId.HasValue) - { - await AuthorizationService.CheckStoreOwnerAsync(input.StoreId.Value, - PaymentsPermissions.Payments.Manage); - } - else - { - await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.CrossStore); - } } return await base.GetListAsync(input); } - + [Authorize(PaymentsPermissions.Payments.Create)] public virtual async Task CreateAsync(CreatePaymentDto input) { // Todo: should avoid duplicate creations. (concurrent lock) var orders = new List(); - + foreach (var orderId in input.OrderIds) { orders.Add(await _orderAppService.GetAsync(orderId)); } - var extraProperties = new Dictionary { { "StoreId", orders.First().StoreId } }; - - await _payableChecker.CheckAsync(input, orders, extraProperties); - - // Todo: should avoid duplicate creations. - - await _distributedEventBus.PublishAsync(new CreatePaymentEto + var createPaymentEto = new CreatePaymentEto { TenantId = CurrentTenant.Id, UserId = CurrentUser.GetId(), diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs index 249a943d..cc21d5ca 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs @@ -21,7 +21,7 @@ namespace EasyAbp.EShop.Payments.Refunds private readonly IPaymentRepository _paymentRepository; private readonly IRefundRepository _repository; - + public RefundAppService( IPaymentRepository paymentRepository, IRefundRepository repository) : base(repository) @@ -35,22 +35,15 @@ namespace EasyAbp.EShop.Payments.Refunds var refund = await base.GetAsync(id); var payment = await _paymentRepository.GetAsync(refund.PaymentId); - + if (payment.UserId != CurrentUser.GetId()) { - if (payment.StoreId.HasValue) - { - await AuthorizationService.CheckStoreOwnerAsync(payment.StoreId.Value, PaymentsPermissions.Refunds.Manage); - } - else - { - await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.Manage); - } + await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.Manage); } return refund; } - + protected override IQueryable CreateFilteredQuery(GetRefundListDto input) { var query = input.UserId.HasValue ? _repository.GetQueryableByUserId(input.UserId.Value) : _repository; @@ -63,16 +56,6 @@ namespace EasyAbp.EShop.Payments.Refunds if (input.UserId != CurrentUser.GetId()) { await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.Manage); - - if (input.StoreId.HasValue) - { - await AuthorizationService.CheckStoreOwnerAsync(input.StoreId.Value, - PaymentsPermissions.Refunds.Manage); - } - else - { - await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.CrossStore); - } } return await base.GetListAsync(input); diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Permissions/BasicStorePermissionAuthorizationHandler.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Permissions/BasicStorePermissionAuthorizationHandler.cs index 5215bcbb..d1b52d89 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Permissions/BasicStorePermissionAuthorizationHandler.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Permissions/BasicStorePermissionAuthorizationHandler.cs @@ -9,13 +9,13 @@ namespace EasyAbp.EShop.Stores.Permissions { public class BasicStorePermissionAuthorizationHandler : AuthorizationHandler { - private readonly IStoreOwnerAppService _storeOwnerAppService; + private readonly IStoreOwnerStore _storeOwnerStore; private readonly IPermissionChecker _permissionChecker; - public BasicStorePermissionAuthorizationHandler(IStoreOwnerAppService storeOwnerAppService, + public BasicStorePermissionAuthorizationHandler(IStoreOwnerStore storeOwnerStore, IPermissionChecker permissionChecker) { - _storeOwnerAppService = storeOwnerAppService; + _storeOwnerStore = storeOwnerStore; _permissionChecker = permissionChecker; } @@ -24,7 +24,7 @@ namespace EasyAbp.EShop.Stores.Permissions var userId = context.User?.FindUserId(); if (userId.HasValue) { - var isStoreOwner = await _storeOwnerAppService.IsStoreOwnerAsync(requirement.StoreId, userId.Value); + var isStoreOwner = await _storeOwnerStore.IsStoreOwnerAsync(requirement.StoreId, userId.Value); if (isStoreOwner) { diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/Dtos/StoreOwnerDto.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/Dtos/StoreOwnerDto.cs index 31157a32..e95dc870 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/Dtos/StoreOwnerDto.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/Dtos/StoreOwnerDto.cs @@ -1,12 +1,15 @@ using System; +using System.ComponentModel.DataAnnotations; using Volo.Abp.Application.Dtos; namespace EasyAbp.EShop.Stores.StoreOwners.Dtos { - public class StoreOwnerDto : AuditedEntityDto + public class StoreOwnerDto : ExtensibleFullAuditedEntityDto { + [Required] public Guid StoreId { get; set; } + [Required] public Guid OwnerId { get; set; } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerAppService.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerAppService.cs index c6223354..48c2f740 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerAppService.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerAppService.cs @@ -6,11 +6,10 @@ using Volo.Abp.Application.Services; namespace EasyAbp.EShop.Stores.StoreOwners { public interface IStoreOwnerAppService : - IReadOnlyAppService< + ICrudAppService< StoreOwnerDto, Guid, GetStoreOwnerListDto> { - Task IsStoreOwnerAsync(Guid storeId, Guid userId); } } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerDuplicatedException.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerDuplicatedException.cs new file mode 100644 index 00000000..1aec6071 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerDuplicatedException.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp; + +namespace EasyAbp.EShop.Stores.StoreOwners +{ + public class StoreOwnerDuplicatedException : BusinessException + { + public StoreOwnerDuplicatedException(Guid storeId, Guid ownerId) : base( + message: $"Owner {ownerId} is duplicate for the store {storeId}") + { + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/CreateUpdateStoreDto.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/CreateUpdateStoreDto.cs index 209fad58..c463f482 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/CreateUpdateStoreDto.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/CreateUpdateStoreDto.cs @@ -10,9 +10,6 @@ namespace EasyAbp.EShop.Stores.Stores.Dtos { [Required] [DisplayName("StoreName")] - public string Name { get; set; } - - [DisplayName("StoreOwner")] - public ICollection OwnerIds { get; set; } + public string Name { get; set; } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/StoreDto.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/StoreDto.cs index f4e247ac..24d11fd8 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/StoreDto.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application.Contracts/EasyAbp/EShop/Stores/Stores/Dtos/StoreDto.cs @@ -1,10 +1,12 @@ using System; +using System.ComponentModel.DataAnnotations; using Volo.Abp.Application.Dtos; namespace EasyAbp.EShop.Stores.Stores.Dtos { public class StoreDto : ExtensibleAuditedEntityDto { + [Required] public string Name { get; set; } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerAppService.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerAppService.cs index 454b9c75..8d9ab163 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerAppService.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerAppService.cs @@ -8,9 +8,13 @@ using Volo.Abp.Application.Services; namespace EasyAbp.EShop.Stores.StoreOwners { - public class StoreOwnerAppService : ReadOnlyAppService, + public class StoreOwnerAppService : CrudAppService, IStoreOwnerAppService { + protected override string CreatePolicyName { get; set; } = StoresPermissions.Stores.Manage; + protected override string DeletePolicyName { get; set; } = StoresPermissions.Stores.Manage; + protected override string UpdatePolicyName { get; set; } = StoresPermissions.Stores.Manage; + protected override string GetPolicyName { get; set; } = StoresPermissions.Stores.Manage; protected override string GetListPolicyName { get; set; } = StoresPermissions.Stores.Manage; private readonly IStoreOwnerRepository _repository; @@ -20,6 +24,16 @@ namespace EasyAbp.EShop.Stores.StoreOwners _repository = repository; } + public override async Task CreateAsync(StoreOwnerDto input) + { + if (await _repository.IsExistAsync(input.StoreId, input.OwnerId)) + { + throw new StoreOwnerDuplicatedException(input.StoreId, input.OwnerId); + } + + return await base.CreateAsync(input); + } + protected override IQueryable CreateFilteredQuery(GetStoreOwnerListDto input) { var queryable = Repository.AsQueryable(); @@ -36,19 +50,5 @@ namespace EasyAbp.EShop.Stores.StoreOwners return queryable; } - - [RemoteService(false)] - public override Task GetAsync(Guid id) - { - throw new NotSupportedException(); - } - - [RemoteService(false)] - public async Task IsStoreOwnerAsync(Guid storeId, Guid userId) - { - var storeOwner = await _repository.FindAsync(x => x.OwnerId == userId && x.StoreId == storeId, false); - - return storeOwner != null; - } } -} +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/Stores/StoreAppService.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/Stores/StoreAppService.cs index 55cb8fd1..1dca0f80 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/Stores/StoreAppService.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/Stores/StoreAppService.cs @@ -1,22 +1,27 @@ -using EasyAbp.EShop.Stores.Stores.Dtos; using System; using System.Threading.Tasks; +using EasyAbp.EShop.Stores.Permissions; +using EasyAbp.EShop.Stores.Stores.Dtos; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; namespace EasyAbp.EShop.Stores.Stores { - public class StoreAppService : CrudAppService, + public class StoreAppService : CrudAppService, IStoreAppService { + protected override string CreatePolicyName { get; set; } = StoresPermissions.Stores.Create; + protected override string DeletePolicyName { get; set; } = StoresPermissions.Stores.Delete; + protected override string UpdatePolicyName { get; set; } = StoresPermissions.Stores.Update; + protected override string GetPolicyName { get; set; } = StoresPermissions.Stores.Default; + protected override string GetListPolicyName { get; set; } = StoresPermissions.Stores.Default; + private readonly IStoreRepository _repository; - private readonly IStoreManager _storeManager; - public StoreAppService(IStoreRepository repository, - IStoreManager storeManager) : base(repository) + public StoreAppService(IStoreRepository repository) : base(repository) { _repository = repository; - _storeManager = storeManager; } public async Task GetDefaultAsync() @@ -24,31 +29,5 @@ namespace EasyAbp.EShop.Stores.Stores // Todo: need to be improved return ObjectMapper.Map(await _repository.FindDefaultStoreAsync()); } - - public override async Task CreateAsync(CreateUpdateStoreDto input) - { - await CheckCreatePolicyAsync(); - - var entity = MapToEntity(input); - - TryToSetTenantId(entity); - - entity = await _storeManager.CreateAsync(entity, input.OwnerIds); - - return MapToGetOutputDto(entity); - } - - public override async Task UpdateAsync(Guid id, CreateUpdateStoreDto input) - { - await CheckUpdatePolicyAsync(); - - var entity = await GetEntityByIdAsync(id); - - MapToEntity(input, entity); - - entity = await _storeManager.UpdateAsync(entity, input.OwnerIds); - - return MapToGetOutputDto(entity); - } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoresApplicationAutoMapperProfile.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoresApplicationAutoMapperProfile.cs index ccb37257..a1ab280a 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoresApplicationAutoMapperProfile.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Application/EasyAbp/EShop/Stores/StoresApplicationAutoMapperProfile.cs @@ -17,11 +17,12 @@ namespace EasyAbp.EShop.Stores CreateMap() .MapExtraProperties(MappingPropertyDefinitionChecks.Both); CreateMap(MemberList.Source) - .MapExtraProperties(MappingPropertyDefinitionChecks.Both) - .ForSourceMember(x => x.OwnerIds, opt => opt.DoNotValidate()); - - CreateMap(); + .MapExtraProperties(MappingPropertyDefinitionChecks.Both); + CreateMap() + .MapExtraProperties(MappingPropertyDefinitionChecks.Both); + CreateMap(MemberList.Source) + .MapExtraProperties(MappingPropertyDefinitionChecks.Both); } } } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/cs.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/cs.json index 35015df9..fee46139 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/cs.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/cs.json @@ -7,6 +7,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/en.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/en.json index 88eb274d..0e45fd75 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/en.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/en.json @@ -8,6 +8,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pl.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pl.json index 5b85c8c4..88fb5d97 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pl.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pl.json @@ -7,6 +7,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pt-BR.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pt-BR.json index 774c1c9e..ce88c998 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pt-BR.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/pt-BR.json @@ -7,6 +7,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/sl.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/sl.json index cf6c73d7..be095251 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/sl.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/sl.json @@ -8,6 +8,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/tr.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/tr.json index 1cd9bcde..03a99240 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/tr.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/tr.json @@ -8,6 +8,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/vi.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/vi.json index 4a8b2d0b..4d44ef7e 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/vi.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/vi.json @@ -7,6 +7,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hans.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hans.json index fdcac995..5f1e7414 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hans.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hans.json @@ -8,6 +8,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hant.json b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hant.json index 33b25c6c..ab03f468 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hant.json +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/Localization/Stores/zh-Hant.json @@ -8,6 +8,11 @@ "CreateStore": "CreateStore", "EditStore": "EditStore", "StoreDeletionConfirmationMessage": "Are you sure to delete the store {0}?", - "SuccessfullyDeleted": "Successfully deleted" + "SuccessfullyDeleted": "Successfully deleted", + "StoreOwner": "StoreOwner", + "Menu:StoreOwner": "MenuStoreOwner", + "CreateStoreOwner": "CreateStoreOwner", + "EditStoreOwner": "EditStoreOwner", + "StoreOwnerDeletionConfirmationMessage": "Are you sure to delete the store owner {0}?" } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerStore.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerStore.cs new file mode 100644 index 00000000..d207047f --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain.Shared/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerStore.cs @@ -0,0 +1,10 @@ +using System; +using System.Threading.Tasks; + +namespace EasyAbp.EShop.Stores.StoreOwners +{ + public interface IStoreOwnerStore + { + Task IsStoreOwnerAsync(Guid storeId, Guid userId); + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp.EShop.Stores.Domain.csproj b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp.EShop.Stores.Domain.csproj index 485f6190..1aa06f22 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp.EShop.Stores.Domain.csproj +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp.EShop.Stores.Domain.csproj @@ -8,6 +8,7 @@ + diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerRepository.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerRepository.cs index 57da4bb7..61dd6e4b 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerRepository.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/IStoreOwnerRepository.cs @@ -11,5 +11,7 @@ namespace EasyAbp.EShop.Stores.StoreOwners Task> GetListByStoreIdAsync(Guid storeId, CancellationToken cancellationToken = default); Task> GetListByOwnerIdAsync(Guid ownerId, CancellationToken cancellationToken = default); + + Task IsExistAsync(Guid storeId, Guid ownerId, CancellationToken cancellationToken = default); } -} +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerCacheItem.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerCacheItem.cs new file mode 100644 index 00000000..9d3edf00 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerCacheItem.cs @@ -0,0 +1,24 @@ +using System; + +namespace EasyAbp.EShop.Stores.StoreOwners +{ + [Serializable] + public class StoreOwnerCacheItem + { + public bool IsOwner { get; set; } + + public StoreOwnerCacheItem() + { + } + + public StoreOwnerCacheItem(bool isOwner) + { + IsOwner = isOwner; + } + + public static string CalculateCacheKey(Guid storeId, Guid userId) + { + return "s:" + storeId.ToString("D") + ",u:" + userId.ToString("D"); + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerStore.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerStore.cs new file mode 100644 index 00000000..bed38fcb --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerStore.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; + +namespace EasyAbp.EShop.Stores.StoreOwners +{ + public class StoreOwnerStore : IStoreOwnerStore, ITransientDependency + { + protected ILogger Logger { get; } + protected IStoreOwnerRepository StoreOwnerRepository { get; } + protected IDistributedCache Cache { get; } + + public StoreOwnerStore(ILogger logger, + IStoreOwnerRepository storeOwnerRepository, + IDistributedCache cache) + { + StoreOwnerRepository = storeOwnerRepository; + Cache = cache; + Logger = logger ?? NullLogger.Instance; + } + + public async Task IsStoreOwnerAsync(Guid storeId, Guid userId) + { + return (await GetCacheItemAsync(storeId, userId)).IsOwner; + } + + protected virtual async Task GetCacheItemAsync(Guid storeId, Guid userId) + { + var cacheKey = CalculateCacheKey(storeId, userId); + Logger.LogDebug($"StoreOwnerStore.GetCacheItemAsync: {cacheKey}"); + + var cacheItem = await Cache.GetAsync(cacheKey); + if (cacheItem != null) + { + Logger.LogDebug($"Found in the cache: {cacheKey}"); + return cacheItem; + } + + Logger.LogDebug($"Not found in the cache: {cacheKey}"); + cacheItem = new StoreOwnerCacheItem(false); + + await SetCacheItemsAsync(storeId, userId, cacheItem); + return cacheItem; + } + + protected virtual async Task SetCacheItemsAsync( + Guid storeId, Guid userId, + StoreOwnerCacheItem currentCacheItem) + { + var storeOwners = await StoreOwnerRepository.GetListByStoreIdAsync(storeId); + Logger.LogDebug( + $"Getting all store owner in store: {storeId}"); + + Logger.LogDebug($"Setting the cache items. Count: {storeOwners.Count}"); + + var cacheItems = new Dictionary(); + foreach (var storeOwner in storeOwners) + { + cacheItems.Add(CalculateCacheKey(storeOwner.StoreId, storeOwner.OwnerId), + new StoreOwnerCacheItem(true)); + + if (storeOwner.StoreId == storeId && storeOwner.OwnerId == userId) + { + currentCacheItem.IsOwner = true; + } + } + + await Cache.SetManyAsync(cacheItems); + Logger.LogDebug($"Finished setting the cache items. Count: {storeOwners.Count}"); + } + + protected virtual string CalculateCacheKey(Guid storeId, Guid userId) + { + return StoreOwnerCacheItem.CalculateCacheKey(storeId, userId); + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreManager.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreManager.cs deleted file mode 100644 index 40a4cecb..00000000 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/IStoreManager.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.Abp.Domain.Services; - -namespace EasyAbp.EShop.Stores.Stores -{ - public interface IStoreManager : IDomainService - { - Task CreateAsync(Store store, IEnumerable ownerIds = null); - - Task UpdateAsync(Store store, IEnumerable ownerIds = null); - } -} diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreManager.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreManager.cs deleted file mode 100644 index 2f8e66e7..00000000 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Domain/EasyAbp/EShop/Stores/Stores/StoreManager.cs +++ /dev/null @@ -1,58 +0,0 @@ -using EasyAbp.EShop.Stores.StoreOwners; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Volo.Abp.Domain.Services; - -namespace EasyAbp.EShop.Stores.Stores -{ - public class StoreManager : DomainService, IStoreManager - { - private readonly IStoreRepository _storeRepository; - private readonly IStoreOwnerRepository _storeOwnerRepository; - - public StoreManager(IStoreRepository storeRepository, - IStoreOwnerRepository storeOwnerRepository) - { - _storeRepository = storeRepository; - _storeOwnerRepository = storeOwnerRepository; - } - - public async Task CreateAsync(Store store, IEnumerable ownerIds = null) - { - store = await _storeRepository.InsertAsync(store); - - await UpdateStoreOwnersAsync(store.Id, ownerIds); - - return store; - } - - public async Task UpdateAsync(Store store, IEnumerable ownerIds = null) - { - store = await _storeRepository.UpdateAsync(store); - - await UpdateStoreOwnersAsync(store.Id, ownerIds); - - return store; - } - - protected virtual async Task UpdateStoreOwnersAsync(Guid storeId, IEnumerable ownerIds) - { - ownerIds ??= new List(); - - var storeOwners = await _storeOwnerRepository.GetListByStoreIdAsync(storeId); - - foreach (var storeOwner in storeOwners.Where(x => !ownerIds.Contains(x.OwnerId)).ToList()) - { - await _storeOwnerRepository.DeleteAsync(storeOwner, true); - } - - foreach (var ownerId in ownerIds.Except(storeOwners.Select(x => x.OwnerId).ToList())) - { - await _storeOwnerRepository.InsertAsync( - new StoreOwner(GuidGenerator.Create(), storeId, ownerId, CurrentTenant.Id), true); - } - } - } -} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/EntityFrameworkCore/StoresDbContextModelCreatingExtensions.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/EntityFrameworkCore/StoresDbContextModelCreatingExtensions.cs index f9b97b84..20e50c5d 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/EntityFrameworkCore/StoresDbContextModelCreatingExtensions.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/EntityFrameworkCore/StoresDbContextModelCreatingExtensions.cs @@ -54,6 +54,9 @@ namespace EasyAbp.EShop.Stores.EntityFrameworkCore b.ToTable(options.TablePrefix + "StoreOwners", options.Schema); b.ConfigureByConvention(); /* Configure more properties here */ + + b.HasIndex(x => new {x.StoreId, x.OwnerId}) + .IsUnique(); }); } } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerRepository.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerRepository.cs index 760b63be..22c096f8 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerRepository.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.EntityFrameworkCore/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerRepository.cs @@ -16,14 +16,25 @@ namespace EasyAbp.EShop.Stores.StoreOwners { } - public async Task> GetListByStoreIdAsync(Guid storeId, CancellationToken cancellationToken = default) + public async Task> GetListByStoreIdAsync(Guid storeId, + CancellationToken cancellationToken = default) { return await GetQueryable().Where(pc => pc.StoreId == storeId).ToListAsync(cancellationToken); } - public async Task> GetListByOwnerIdAsync(Guid ownerId, CancellationToken cancellationToken = default) + public async Task> GetListByOwnerIdAsync(Guid ownerId, + CancellationToken cancellationToken = default) { return await GetQueryable().Where(pc => pc.OwnerId == ownerId).ToListAsync(cancellationToken); } + + public async Task IsExistAsync(Guid storeId, Guid ownerId, CancellationToken cancellationToken = default) + { + var storeOwner = await GetQueryable().FirstOrDefaultAsync( + x => x.StoreId == storeId && x.OwnerId == ownerId, + cancellationToken: cancellationToken); + + return storeOwner != null; + } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.HttpApi/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerController.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.HttpApi/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerController.cs index 81d232b2..74cc09af 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.HttpApi/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerController.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.HttpApi/EasyAbp/EShop/Stores/StoreOwners/StoreOwnerController.cs @@ -1,13 +1,13 @@ -using EasyAbp.EShop.Stores.StoreOwners.Dtos; -using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; +using EasyAbp.EShop.Stores.StoreOwners.Dtos; +using Microsoft.AspNetCore.Mvc; using Volo.Abp; using Volo.Abp.Application.Dtos; namespace EasyAbp.EShop.Stores.StoreOwners { - [RemoteService(Name = "EShopStores")] + [RemoteService(Name = "EShopStoreOwners")] [Route("/api/eShop/stores/storeOwner")] public class StoreOwnerController : StoresController { @@ -18,8 +18,8 @@ namespace EasyAbp.EShop.Stores.StoreOwners _service = service; } - [NonAction] - [RemoteService(false)] + [HttpGet] + [Route("{id}")] public Task GetAsync(Guid id) { return _service.GetAsync(id); @@ -30,5 +30,25 @@ namespace EasyAbp.EShop.Stores.StoreOwners { return _service.GetListAsync(input); } + + [HttpPost] + public Task CreateAsync(StoreOwnerDto input) + { + return _service.CreateAsync(input); + } + + [HttpPut] + [Route("{id}")] + public Task UpdateAsync(Guid id, StoreOwnerDto input) + { + return _service.UpdateAsync(id, input); + } + + [HttpDelete] + [Route("{id}")] + public Task DeleteAsync(Guid id) + { + return _service.DeleteAsync(id); + } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/EasyAbp.EShop.Stores.Web.csproj b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/EasyAbp.EShop.Stores.Web.csproj index 5657a4f8..01386386 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/EasyAbp.EShop.Stores.Web.csproj +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/EasyAbp.EShop.Stores.Web.csproj @@ -32,10 +32,44 @@ + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + + + CreateModal.cshtml + + + EditModal.cshtml + + + Index.cshtml + + + CreateModal.cshtml + + + EditModal.cshtml + + + Index.cshtml + + + diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenuContributor.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenuContributor.cs index fb91ec4c..a347b8d8 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenuContributor.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenuContributor.cs @@ -29,6 +29,13 @@ namespace EasyAbp.EShop.Stores.Web.Menus ); } + if (await context.IsGrantedAsync(StoresPermissions.Stores.Manage)) + { + storeManagementMenuItem.AddItem( + new ApplicationMenuItem(StoresMenus.StoreOwner, l["Menu:StoreOwner"], "/EShop/Stores/StoreOwners/StoreOwner") + ); + } + if (!storeManagementMenuItem.Items.IsNullOrEmpty()) { var eShopMenuItem = context.Menu.Items.GetOrAdd(i => i.Name == StoresMenus.ModuleGroupPrefix, diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenus.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenus.cs index fc6bf9ec..8147b6a2 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenus.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Menus/StoresMenus.cs @@ -7,6 +7,8 @@ public const string Prefix = ModuleGroupPrefix + ".Stores"; public const string Store = Prefix + ".Store"; + + public const string StoreOwner = Prefix + ".StoreOwner"; //Add your menu items here... //public const string Home = Prefix + ".MyNewMenuItem"; diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml new file mode 100644 index 00000000..b7055758 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml @@ -0,0 +1,19 @@ +@page +@using EasyAbp.EShop.Stores.Localization +@using Microsoft.AspNetCore.Mvc.Localization +@using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal +@inject IHtmlLocalizer L +@model CreateModalModel +@{ + Layout = null; +} + + + + + + + + + \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml.cs new file mode 100644 index 00000000..55e7f58c --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/CreateModal.cshtml.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using EasyAbp.EShop.Stores.StoreOwners; +using EasyAbp.EShop.Stores.StoreOwners.Dtos; +using EasyAbp.EShop.Stores.Stores; +using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner.ViewModels; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Identity; + +namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner +{ + public class CreateModalModel : StoresPageModel + { + [BindProperty] + public CreateEditStoreOwnerViewModel StoreOwner { get; set; } + + private readonly IStoreAppService _storeService; + private readonly IIdentityUserAppService _userAppService; + private readonly IStoreOwnerAppService _storeOwnerAppService; + + public CreateModalModel(IStoreAppService storeService, + IIdentityUserAppService userAppService, + IStoreOwnerAppService storeOwnerAppService) + { + _storeService = storeService; + _userAppService = userAppService; + _storeOwnerAppService = storeOwnerAppService; + } + + public virtual Task OnGetAsync() + { + return Task.CompletedTask; + } + + public async Task OnPostAsync() + { + var createDto = ObjectMapper.Map(StoreOwner); + var storeOwner = await _storeOwnerAppService.CreateAsync(createDto); + + return NoContent(); + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml new file mode 100644 index 00000000..caba590b --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml @@ -0,0 +1,20 @@ +@page +@using EasyAbp.EShop.Stores.Localization +@using Microsoft.AspNetCore.Mvc.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal +@using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner +@inject IHtmlLocalizer L +@model EditModalModel +@{ + Layout = null; +} + + + + + + + + + + \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml.cs new file mode 100644 index 00000000..e4baa4d0 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/EditModal.cshtml.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using EasyAbp.EShop.Stores.StoreOwners; +using EasyAbp.EShop.Stores.StoreOwners.Dtos; +using EasyAbp.EShop.Stores.Stores; +using EasyAbp.EShop.Stores.Stores.Dtos; +using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner.ViewModels; +using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.Stores.Store.ViewModels; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Identity; + +namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner +{ + public class EditModalModel : StoresPageModel + { + [HiddenInput] + [BindProperty(SupportsGet = true)] + public Guid Id { get; set; } + + [BindProperty] public CreateEditStoreOwnerViewModel StoreOwner { get; set; } + + private readonly IStoreAppService _storeService; + private readonly IIdentityUserAppService _userAppService; + private readonly IStoreOwnerAppService _storeOwnerAppService; + + public EditModalModel(IStoreAppService storeService, + IIdentityUserAppService userAppService, + IStoreOwnerAppService storeOwnerAppService) + { + _storeService = storeService; + _userAppService = userAppService; + _storeOwnerAppService = storeOwnerAppService; + } + + public async Task OnGetAsync() + { + + var dto = await _storeOwnerAppService.GetAsync(Id); + StoreOwner = ObjectMapper.Map(dto); + } + + public async Task OnPostAsync() + { + await _storeOwnerAppService.UpdateAsync(Id, + ObjectMapper.Map( StoreOwner)); + return NoContent(); + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml new file mode 100644 index 00000000..c628fd00 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml @@ -0,0 +1,61 @@ +@page +@using EasyAbp.EShop.Stores.Permissions +@using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner +@using EasyAbp.EShop.Stores.Localization +@using EasyAbp.EShop.Stores.Web.Menus +@using Microsoft.AspNetCore.Authorization +@using Microsoft.AspNetCore.Mvc.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Layout +@model IndexModel +@inject IPageLayout PageLayout +@inject IHtmlLocalizer L +@inject IAuthorizationService Authorization +@{ + PageLayout.Content.Title = L["StoreOwner"].Value; + PageLayout.Content.BreadCrumb.Add(L["Menu:StoreOwner"].Value); + PageLayout.Content.MenuItemName = StoresMenus.StoreOwner; +} + +@section scripts +{ + +} + +@section styles +{ + +} + + + + + + + + @L["StoreOwner"] + + + @if (await Authorization.IsGrantedAsync(StoresPermissions.Stores.Manage)) + { + + } + + + + + + + + @L["Actions"] + @L["StoreName"] + @L["OwnerName"] + + + + + \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml.cs new file mode 100644 index 00000000..e9c80c50 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.cshtml.cs @@ -0,0 +1,21 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner +{ + public class IndexModel : StoresPageModel + { + [BindProperty(SupportsGet = true)] + public Guid? StoreId { get; set; } + + public IndexModel() + { + } + + public Task OnGetAsync() + { + return Task.CompletedTask; + } + } +} diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.css b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.css new file mode 100644 index 00000000..e69de29b diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.js b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.js new file mode 100644 index 00000000..b4930ca6 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/Index.js @@ -0,0 +1,87 @@ +$(function () { + + var l = abp.localization.getResource('EasyAbpEShopStores'); + + var service = easyAbp.eShop.stores.storeOwners.storeOwner; + var storeService = easyAbp.eShop.stores.stores.store; + var userService = volo.abp.identity.identityUser; + var createModal = new abp.ModalManager(abp.appPath + 'EShop/Stores/StoreOwners/StoreOwner/CreateModal'); + var editModal = new abp.ModalManager(abp.appPath + 'EShop/Stores/StoreOwners/StoreOwner/EditModal'); + + var dataTable = $('#StoreOwnerTable').DataTable(abp.libs.datatables.normalizeConfiguration({ + processing: true, + serverSide: true, + paging: true, + searching: false, + autoWidth: false, + scrollCollapse: true, + order: [[1, "asc"]], + ajax: abp.libs.datatables.createAjax(service.getList, function () { + return {storeId: storeId} + }), + columnDefs: [ + { + rowAction: { + items: + [ + { + text: l('Edit'), + action: function (data) { + editModal.open({id: data.record.id}); + } + }, + { + text: l('Delete'), + confirmMessage: function (data) { + return l('StoreDeletionConfirmationMessage', data.record.id); + }, + action: function (data) { + service.delete(data.record.id) + .then(function () { + abp.notify.info(l('SuccessfullyDeleted')); + dataTable.ajax.reload(); + }); + } + } + ] + } + }, + { + data: "storeId", + render: function (data, type, row, meta) { + var currentCell = $("#StoreOwnerTable").DataTable().cells({"row":meta.row, "column":meta.col}).nodes(0); + storeService.get(data).then( + x => { + $(currentCell).html(x.name); + }); + return '...'; + } + }, + { + data: "ownerId", + render: function (data, type, row, meta) { + var currentCell = $("#StoreOwnerTable").DataTable().cells({"row":meta.row, "column":meta.col}).nodes(0); + userService.get(data).then( + x=>{ + $(currentCell).html(x.userName); + } + ); + return '...'; + } + } + ] + })); + + createModal.onResult(function () { + dataTable.ajax.reload(); + }); + + editModal.onResult(function () { + dataTable.ajax.reload(); + }); + + $('#NewStoreOwnerButton').click(function (e) { + e.preventDefault(); + createModal.open({storeId: storeId}); + }); +}); \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/ViewModels/CreateStoreOwnerViewModel.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/ViewModels/CreateStoreOwnerViewModel.cs new file mode 100644 index 00000000..70a202a0 --- /dev/null +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/StoreOwners/StoreOwner/ViewModels/CreateStoreOwnerViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form; +using Volo.Abp.ObjectExtending; + +namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner.ViewModels +{ + public class CreateEditStoreOwnerViewModel : ExtensibleObject + { + [Required] + public Guid StoreId { get; set; } + + + [Required] + public Guid OwnerId { get; set; } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/CreateModal.cshtml.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/CreateModal.cshtml.cs index 315e88dc..a0c2a3e0 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/CreateModal.cshtml.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/CreateModal.cshtml.cs @@ -39,7 +39,7 @@ namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.Stores.Store public async Task OnPostAsync() { var createDto = ObjectMapper.Map(Store); - var product = await _service.CreateAsync(createDto); + var store = await _service.CreateAsync(createDto); return NoContent(); } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/EditModal.cshtml.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/EditModal.cshtml.cs index 77e07738..de233e00 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/EditModal.cshtml.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/EditModal.cshtml.cs @@ -23,36 +23,17 @@ namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.Stores.Store [BindProperty] public CreateEditStoreViewModel Store { get; set; } - public ICollection StoreOwners { get; set; } - private readonly IStoreAppService _service; - private readonly IIdentityUserAppService _userAppService; - private readonly IStoreOwnerAppService _storeOwnerAppService; - public EditModalModel(IStoreAppService service, - IIdentityUserAppService userAppService, - IStoreOwnerAppService storeOwnerAppService) + public EditModalModel(IStoreAppService service) { _service = service; - _userAppService = userAppService; - _storeOwnerAppService = storeOwnerAppService; } public async Task OnGetAsync() { - StoreOwners = - (await _userAppService.GetListAsync(new GetIdentityUsersInput - { MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount })).Items - .Select(x => new SelectListItem(x.UserName, x.Id.ToString())).ToList(); - var dto = await _service.GetAsync(Id); Store = ObjectMapper.Map(dto); - - Store.OwnerIds = (await _storeOwnerAppService.GetListAsync(new GetStoreOwnerListDto - { - StoreId = Id, - MaxResultCount = LimitedResultRequestDto.MaxMaxResultCount - })).Items.Select(x => x.OwnerId).ToList(); } public async Task OnPostAsync() diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/Index.cshtml b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/Index.cshtml index ffecf74d..20576000 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/Index.cshtml +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/Index.cshtml @@ -11,8 +11,8 @@ @inject IHtmlLocalizer L @inject IAuthorizationService Authorization @{ - PageLayout.Content.Title = L["BasketItem"].Value; - PageLayout.Content.BreadCrumb.Add(L["Menu:BasketItem"].Value); + PageLayout.Content.Title = L["Store"].Value; + PageLayout.Content.BreadCrumb.Add(L["Menu:Store"].Value); PageLayout.Content.MenuItemName = StoresMenus.Store; } diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/ViewModels/CreateEditStoreViewModel.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/ViewModels/CreateEditStoreViewModel.cs index cddc2499..87dc5aa0 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/ViewModels/CreateEditStoreViewModel.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/Pages/EShop/Stores/Stores/Store/ViewModels/CreateEditStoreViewModel.cs @@ -11,10 +11,5 @@ namespace EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.Stores.Store.ViewModels [Required] [Display(Name = "StoreName")] public string Name { get; set; } - - - [SelectItems("StoreOwners")] - [Display(Name = "StoreOwner")] - public List OwnerIds { get; set; } } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/StoresWebAutoMapperProfile.cs b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/StoresWebAutoMapperProfile.cs index beb7bfc1..62674ee0 100644 --- a/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/StoresWebAutoMapperProfile.cs +++ b/modules/EasyAbp.EShop.Stores/src/EasyAbp.EShop.Stores.Web/StoresWebAutoMapperProfile.cs @@ -1,5 +1,7 @@ using EasyAbp.EShop.Stores.Stores.Dtos; using AutoMapper; +using EasyAbp.EShop.Stores.StoreOwners.Dtos; +using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.StoreOwners.StoreOwner.ViewModels; using EasyAbp.EShop.Stores.Web.Pages.EShop.Stores.Stores.Store.ViewModels; using Volo.Abp.AutoMapper; using Volo.Abp.ObjectExtending; @@ -14,9 +16,13 @@ namespace EasyAbp.EShop.Stores.Web * Alternatively, you can split your mapping configurations * into multiple profile classes for a better organization. */ CreateMap() - .MapExtraProperties(MappingPropertyDefinitionChecks.Both) - .Ignore(x=>x.OwnerIds); - CreateMap() + .MapExtraProperties(MappingPropertyDefinitionChecks.Both); + CreateMap(MemberList.Source) + .MapExtraProperties(MappingPropertyDefinitionChecks.Both); + + CreateMap() + .MapExtraProperties(MappingPropertyDefinitionChecks.Both); + CreateMap(MemberList.Source) .MapExtraProperties(MappingPropertyDefinitionChecks.Both); } }