コード例 #1
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        public virtual async Task <bool> IsInventorySufficientAsync(Product product, ProductSku productSku, Guid storeId, int quantity)
        {
            var inventoryData = await GetInventoryProviderOrDefault(product, productSku)
                                .GetInventoryDataAsync(product, productSku, storeId);

            return(product.InventoryStrategy == InventoryStrategy.NoNeed || inventoryData.Inventory - quantity >= 0);
        }
コード例 #2
0
 public ConsumeInventoryModel(Product product, ProductSku productSku, Guid storeId, int quantity)
 {
     Product    = product;
     ProductSku = productSku;
     StoreId    = storeId;
     Quantity   = quantity;
 }
コード例 #3
0
        public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, int quantity,
                                                                 bool increaseSold)
        {
            var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, productSku.Id);

            return(await(await _productInventoryProviderResolver.GetAsync(product))
                   .TryReduceInventoryAsync(model, quantity, increaseSold));
        }
コード例 #4
0
        public virtual async Task <Product> UpdateSkuAsync(Product product, ProductSku productSku)
        {
            await CheckProductSkuNameUniqueAsync(product, productSku);

            await CheckProductDetailAsync(product);

            return(await _productRepository.UpdateAsync(product, true));
        }
コード例 #5
0
        public virtual async Task <bool> IsInventorySufficientAsync(Product product, ProductSku productSku, int quantity)
        {
            var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, productSku.Id);

            var inventoryData =
                await(await _productInventoryProviderResolver.GetAsync(product)).GetInventoryDataAsync(model);

            return(product.InventoryStrategy == InventoryStrategy.NoNeed || inventoryData.Inventory - quantity >= 0);
        }
コード例 #6
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        protected virtual Task CheckSkuAttributeOptionsAsync(Product product, ProductSku productSku)
        {
            if (product.ProductSkus.Where(sku => sku.Id != productSku.Id).FirstOrDefault(sku =>
                                                                                         sku.SerializedAttributeOptionIds.Equals(productSku.SerializedAttributeOptionIds)) != null)
            {
                throw new ProductSkuDuplicatedException(product.Id, productSku.SerializedAttributeOptionIds);
            }

            return(Task.CompletedTask);
        }
コード例 #7
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        public virtual async Task <decimal> GetDiscountedPriceAsync(Product product, ProductSku productSku, Guid storeId)
        {
            var currentPrice = productSku.Price;

            foreach (var provider in ServiceProvider.GetServices <IProductDiscountProvider>())
            {
                currentPrice = await provider.GetDiscountedPriceAsync(product, productSku, storeId, currentPrice);
            }

            return(currentPrice);
        }
コード例 #8
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        public virtual async Task <Product> CreateSkuAsync(Product product, ProductSku productSku)
        {
            // productSku.SetSerializedAttributeOptionIds(await _attributeOptionIdsSerializer.FormatAsync(productSku.SerializedAttributeOptionIds));

            await CheckSkuAttributeOptionsAsync(product, productSku);

            await CheckProductSkuNameUniqueAsync(product, productSku);

            productSku.TrimCode();

            product.ProductSkus.AddIfNotContains(productSku);

            return(await _productRepository.UpdateAsync(product, true));
        }
コード例 #9
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        protected virtual Task CheckProductSkuNameUniqueAsync(Product product, ProductSku productSku)
        {
            if (productSku.Name.IsNullOrEmpty())
            {
                return(Task.CompletedTask);
            }

            if (product.ProductSkus.Where(sku => sku.Id != productSku.Id)
                .FirstOrDefault(sku => sku.Name == productSku.Name) != null)
            {
                throw new ProductSkuCodeDuplicatedException(product.Id, productSku.Name);
            }

            return(Task.CompletedTask);
        }
コード例 #10
0
        public async Task Should_Use_Fake_Inventory_Provider()
        {
            var product2 = new Product(ProductsTestData.Product2Id, null, ProductsTestData.Store1Id, "Default",
                                       ProductsTestData.ProductDetails2Id, "Ball", "Ball", InventoryStrategy.NoNeed, "Fake", true, false,
                                       false, null, null, 0);

            await ProductManager.CreateAsync(product2);

            var fakeSku = new ProductSku(Guid.NewGuid(), "[]", null, "USD", null, 0m, 1, 1, null, null, null);

            var inventoryDataModel = await ProductManager.GetInventoryDataAsync(product2, fakeSku);

            inventoryDataModel.ShouldNotBeNull();
            inventoryDataModel.Inventory.ShouldBe(9998);
        }
コード例 #11
0
        protected virtual async Task CheckSkuAttributeOptionsAsync(Product product, ProductSku productSku)
        {
            var attributeOptionIds =
                (await _attributeOptionIdsSerializer.DeserializeAsync(productSku.SerializedAttributeOptionIds))
                .ToList();

            if (!product.ProductAttributes.TrueForAll(attribute =>
                                                      attribute.ProductAttributeOptions.Select(option => option.Id).Intersect(attributeOptionIds)
                                                      .Count() == 1))
            {
                throw new ProductSkuIncorrectAttributeOptionsException(product.Id,
                                                                       productSku.SerializedAttributeOptionIds);
            }

            if (product.ProductSkus.Where(sku => sku.Id != productSku.Id).FirstOrDefault(sku =>
                                                                                         sku.SerializedAttributeOptionIds.Equals(productSku.SerializedAttributeOptionIds)) != null)
            {
                throw new ProductSkuDuplicatedException(product.Id, productSku.SerializedAttributeOptionIds);
            }
        }
コード例 #12
0
ファイル: ProductManager.cs プロジェクト: yinchang0626/EShop
 public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku)
 {
     return(await _productInventoryProvider.GetInventoryDataAsync(product, productSku));
 }
コード例 #13
0
        public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity, bool increaseSold)
        {
            var productInventory = await _productInventoryRepository.GetAsync(x => x.ProductSkuId == productSku.Id);

            return(await TryReduceInventoryAsync(productInventory, quantity, increaseSold));
        }
コード例 #14
0
 public virtual Task <decimal> GetPriceAsync(Product product, ProductSku productSku)
 {
     return(Task.FromResult(productSku.Price));
 }
コード例 #15
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        protected virtual IProductInventoryProvider GetInventoryProviderOrDefault(Product product, ProductSku productSku)
        {
            var providerName = !productSku.SpecifiedInventoryProviderName.IsNullOrWhiteSpace()
                ? productSku.SpecifiedInventoryProviderName
                : !product.SpecifiedInventoryProviderName.IsNullOrWhiteSpace()
                    ? product.SpecifiedInventoryProviderName
                    : "Default";

            InventoryProviders ??= ServiceProvider.GetServices <IProductInventoryProvider>()
            .ToDictionary(p => p.ProviderName, p => p);

            return(InventoryProviders.GetOrDefault(providerName) ?? InventoryProviders["Default"]);
        }
コード例 #16
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
 public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity, bool increaseSold)
 {
     return(await GetInventoryProviderOrDefault(product, productSku)
            .TryReduceInventoryAsync(product, productSku, storeId, quantity, increaseSold));
 }
コード例 #17
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
 public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(await GetInventoryProviderOrDefault(product, productSku)
            .GetInventoryDataAsync(product, productSku, storeId));
 }
コード例 #18
0
 public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity)
 {
     return(await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, storeId, quantity));
 }
コード例 #19
0
ファイル: ProductManager.cs プロジェクト: yuxueliang/EShop
        public virtual async Task <Product> DeleteSkuAsync(Product product, ProductSku productSku)
        {
            product.ProductSkus.Remove(productSku);

            return(await _productRepository.UpdateAsync(product, true));
        }
コード例 #20
0
 public virtual async Task <bool> TryIncreaseInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity, bool reduceSold)
 {
     return(await _productInventoryProvider.TryIncreaseInventoryAsync(product, productSku, storeId, quantity, reduceSold));
 }
コード例 #21
0
        public virtual async Task <PriceDataModel> GetRealPriceAsync(Product product, ProductSku productSku)
        {
            var price = await _productPriceProvider.GetPriceAsync(product, productSku);

            var discountedPrice = price;

            // Todo: provider execution ordering.
            foreach (var provider in LazyServiceProvider.LazyGetService <IEnumerable <IProductDiscountProvider> >())
            {
                discountedPrice = await provider.GetDiscountedPriceAsync(product, productSku, discountedPrice);
            }

            return(new PriceDataModel
            {
                Price = price,
                DiscountedPrice = discountedPrice
            });
        }
コード例 #22
0
 public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(await _productInventoryRepository.GetInventoryDataAsync(productSku.Id));
 }
コード例 #23
0
 public virtual async Task <int> GetInventoryAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(await _productInventoryProvider.GetInventoryAsync(product, productSku, storeId));
 }
コード例 #24
0
 public virtual Task <int> GetInventoryAsync(Product product, ProductSku productSku, Guid storeId)
 {
     return(Task.FromResult(productSku.Inventory));
 }
コード例 #25
0
ファイル: ProductManager.cs プロジェクト: yinchang0626/EShop
 public virtual async Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, int quantity, bool increaseSold)
 {
     return(await _productInventoryProvider.TryReduceInventoryAsync(product, productSku, quantity, increaseSold));
 }
コード例 #26
0
        public virtual async Task <PriceDataModel> GetProductPriceAsync(Product product, ProductSku productSku, Guid storeId)
        {
            var price = await _productPriceProvider.GetPriceAsync(product, productSku, storeId);

            var discountedPrice = price;

            foreach (var provider in ServiceProvider.GetServices <IProductDiscountProvider>())
            {
                discountedPrice = await provider.GetDiscountedPriceAsync(product, productSku, storeId, discountedPrice);
            }

            return(new PriceDataModel
            {
                Price = price,
                DiscountedPrice = discountedPrice
            });
        }
コード例 #27
0
 public virtual Task <bool> TryReduceInventoryAsync(Product product, ProductSku productSku, Guid storeId, int quantity)
 {
     return(Task.FromResult(productSku.TryReduceInventory(quantity)));
 }
コード例 #28
0
        public virtual async Task <InventoryDataModel> GetInventoryDataAsync(Product product, ProductSku productSku)
        {
            var model = new InventoryQueryModel(product.TenantId, product.StoreId, product.Id, productSku.Id);

            return(await(await _productInventoryProviderResolver.GetAsync(product)).GetInventoryDataAsync(model));
        }