示例#1
0
    public virtual async Task <Money?> GetAssetCategoryBookingUnitPriceAsync(CreateOrderDto input,
                                                                             CreateOrderLineDto inputOrderLine, Currency effectiveCurrency)
    {
        var productAssetCategory = (await _productAssetCategoryAppService.GetListAsync(
                                        new GetProductAssetCategoryListDto
        {
            MaxResultCount = 1,
            StoreId = input.StoreId,
            ProductId = inputOrderLine.ProductId,
            ProductSkuId = inputOrderLine.ProductSkuId,
            AssetCategoryId = inputOrderLine.GetBookingAssetCategoryId(),
            PeriodSchemeId = inputOrderLine.GetBookingPeriodSchemeId()
        }
                                        )).Items.First();

        var productAssetCategoryPeriod =
            productAssetCategory.Periods.FirstOrDefault(x => x.PeriodId == inputOrderLine.GetBookingPeriodId());

        if (productAssetCategoryPeriod is not null)
        {
            await CheckCurrencyAsync(productAssetCategoryPeriod.Currency, effectiveCurrency);

            return(new Money(productAssetCategoryPeriod.Price, effectiveCurrency));
        }

        if (productAssetCategory.Price.HasValue)
        {
            await CheckCurrencyAsync(productAssetCategory.Currency, effectiveCurrency);

            return(new Money(productAssetCategory.Price.Value, effectiveCurrency));
        }

        return(null);
    }
        protected virtual async Task <bool> IsAssetCategoryInfoValidAsync(CreateOrderLineDto orderLine,
                                                                          OrderCreationResource resource)
        {
            var mapping = (await _grantedStoreAppService.GetListAsync(new GetGrantedStoreListDto
            {
                MaxResultCount = 1,
                StoreId = resource.Input.StoreId,
                AssetCategoryId = orderLine.GetBookingAssetCategoryId()
            })).Items.FirstOrDefault();

            if (mapping is null)
            {
                mapping = (await _grantedStoreAppService.GetListAsync(new GetGrantedStoreListDto
                {
                    MaxResultCount = 1,
                    AllowAll = true
                })).Items.FirstOrDefault();
            }

            if (mapping is null)
            {
                return(false);
            }

            var productAssetCategory = (await _productAssetCategoryAppService.GetListAsync(
                                            new GetProductAssetCategoryListDto
            {
                MaxResultCount = 1,
                StoreId = resource.Input.StoreId,
                ProductId = orderLine.ProductId,
                ProductSkuId = orderLine.ProductSkuId,
                AssetCategoryId = orderLine.GetBookingAssetCategoryId(),
                PeriodSchemeId = orderLine.GetBookingPeriodSchemeId()
            }
                                            )).Items.FirstOrDefault();

            return(productAssetCategory is not null);
        }