Пример #1
0
        public override async Task <BasketItemDto> GetAsync(Guid id)
        {
            await CheckGetPolicyAsync();

            var item = await GetEntityByIdAsync(id);

            if (item.UserId != CurrentUser.GetId() && !await IsCurrentUserManagerAsync())
            {
                throw new AbpAuthorizationException();
            }

            var productUpdate = await _productUpdateRepository.FindAsync(x => x.ProductSkuId == item.ProductSkuId);

            if (productUpdate != null)
            {
                var itemUpdateTime    = item.LastModificationTime ?? item.CreationTime;
                var productUpdateTime = productUpdate.LastModificationTime ?? productUpdate.CreationTime;

                if (itemUpdateTime < productUpdateTime)
                {
                    var productDto = await _productAppService.GetAsync(item.ProductId, item.StoreId);

                    await UpdateProductDataAsync(item.Quantity, item, productDto);

                    await _repository.UpdateAsync(item, true);
                }
            }

            return(await MapToGetOutputDtoAsync(item));
        }
        protected virtual async Task UpdateAsync(Guid skuId)
        {
            var entity = await _productUpdateRepository.FindAsync(x => x.ProductSkuId == skuId);

            if (entity == null)
            {
                entity = new ProductUpdate(_guidGenerator.Create(), skuId);

                await _productUpdateRepository.InsertAsync(entity);
            }
            else
            {
                await _productUpdateRepository.UpdateAsync(entity);
            }
        }