示例#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);
    }
示例#2
0
        public IActionResult UpdateOrderLineInOrder(long orderId, [FromBody] CreateOrderLineDto createOrderLineDto)
        {
            try
            {
                var order = _unitOfWork.Orders.GetOrderWithOrderLines(orderId);

                if (order == null)
                {
                    return(BadRequest("Order Not Found"));
                }


                Result <Quantity> quantityOrError = Quantity.Create(createOrderLineDto.Quantity);
                Result <Tax>      taxOrError      = Tax.Create(createOrderLineDto.Tax);

                Result result = Result.Combine(quantityOrError, taxOrError);
                if (result.IsFailure)
                {
                    return(BadRequest(result.Error));
                }

                order.UpdateOrderLine(createOrderLineDto.Id, createOrderLineDto.Note, quantityOrError.Value, taxOrError.Value);

                _unitOfWork.Complete();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
示例#3
0
        protected virtual async Task <OrderLine> GenerateOrderLineAsync(CreateOrderDto input,
                                                                        CreateOrderLineDto inputOrderLine, Dictionary <Guid, ProductDto> productDict)
        {
            var product    = productDict[inputOrderLine.ProductId];
            var productSku = product.GetSkuById(inputOrderLine.ProductSkuId);

            if (!inputOrderLine.Quantity.IsBetween(productSku.OrderMinQuantity, productSku.OrderMaxQuantity))
            {
                throw new OrderLineInvalidQuantityException(product.Id, productSku.Id, inputOrderLine.Quantity);
            }

            var totalPrice = productSku.Price * inputOrderLine.Quantity;

            return(new OrderLine(
                       id: _guidGenerator.Create(),
                       productId: product.Id,
                       productSkuId: productSku.Id,
                       productModificationTime: product.LastModificationTime ?? product.CreationTime,
                       productDetailModificationTime: productSku.LastModificationTime ?? productSku.CreationTime,
                       productGroupName: product.ProductGroupName,
                       productGroupDisplayName: product.ProductGroupDisplayName,
                       productUniqueName: product.UniqueName,
                       productDisplayName: product.DisplayName,
                       skuName: productSku.Name,
                       skuDescription: await _productSkuDescriptionProvider.GenerateAsync(product, productSku),
                       mediaResources: product.MediaResources,
                       currency: productSku.Currency,
                       unitPrice: productSku.Price,
                       totalPrice: totalPrice,
                       totalDiscount: 0,
                       actualTotalPrice: totalPrice,
                       quantity: inputOrderLine.Quantity
                       ));
        }
    public async Task <Money?> GetUnitPriceOrNullAsync(CreateOrderDto input, CreateOrderLineDto inputOrderLine,
                                                       ProductDto product, ProductSkuDto productSku, Currency effectiveCurrency)
    {
        if (inputOrderLine.ProductSkuId == OrderTestData.ProductSku3Id)
        {
            return(new Money(Sku3UnitPrice, effectiveCurrency));
        }

        return(null);
    }
        protected virtual async Task <bool> IsPeriodInfoValidAsync(CreateOrderLineDto orderLine)
        {
            var periodSchemeId = orderLine.GetBookingPeriodSchemeId();
            var periodId       = orderLine.GetBookingPeriodId();

            var periodScheme = await _periodSchemeAppService.GetAsync(periodSchemeId);

            var period = periodScheme.Periods.Find(x => x.Id == periodId);

            return(period is not null);
        }
示例#6
0
        protected virtual async Task <OrderLine> GenerateOrderLineAsync(CreateOrderDto input,
                                                                        CreateOrderLineDto inputOrderLine, Dictionary <Guid, ProductDto> productDict,
                                                                        Dictionary <Guid, ProductDetailDto> productDetailDict, Currency effectiveCurrency)
        {
            var product    = productDict[inputOrderLine.ProductId];
            var productSku = product.GetSkuById(inputOrderLine.ProductSkuId);

            if (productSku.Currency != effectiveCurrency.Code)
            {
                throw new UnexpectedCurrencyException(effectiveCurrency.Code);
            }

            var productDetailId = productSku.ProductDetailId ?? product.ProductDetailId;
            var productDetail   = productDetailId.HasValue ? productDetailDict[productDetailId.Value] : null;

            if (!inputOrderLine.Quantity.IsBetween(productSku.OrderMinQuantity, productSku.OrderMaxQuantity))
            {
                throw new OrderLineInvalidQuantityException(product.Id, productSku.Id, inputOrderLine.Quantity);
            }

            var unitPrice = await GetUnitPriceAsync(input, inputOrderLine, product, productSku, effectiveCurrency);

            var totalPrice = unitPrice * inputOrderLine.Quantity;

            var orderLine = new OrderLine(
                id: _guidGenerator.Create(),
                productId: product.Id,
                productSkuId: productSku.Id,
                productDetailId: productDetailId,
                productModificationTime: product.LastModificationTime ?? product.CreationTime,
                productDetailModificationTime: productDetail?.LastModificationTime ?? productDetail?.CreationTime,
                productGroupName: product.ProductGroupName,
                productGroupDisplayName: product.ProductGroupDisplayName,
                productUniqueName: product.UniqueName,
                productDisplayName: product.DisplayName,
                skuName: productSku.Name,
                skuDescription: await _productSkuDescriptionProvider.GenerateAsync(product, productSku),
                mediaResources: product.MediaResources,
                currency: productSku.Currency,
                unitPrice: unitPrice.Amount,
                totalPrice: totalPrice.Amount,
                totalDiscount: 0,
                actualTotalPrice: totalPrice.Amount,
                quantity: inputOrderLine.Quantity
                );

            inputOrderLine.MapExtraPropertiesTo(orderLine, MappingPropertyDefinitionChecks.Destination);

            return(orderLine);
        }
    public async Task Should_Override_Booking_Price()
    {
        var orderAppService = ServiceProvider.GetRequiredService <IOrderAppService>();

        var orderLine1 = new CreateOrderLineDto
        {
            ProductId    = BookingTestConsts.BookingProduct1Id,
            ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id,
            Quantity     = 1
        };

        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId,
                               BookingTestConsts.PeriodScheme1Id);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingAssetId, BookingTestConsts.Asset1Id);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime,
                               BookingTestConsts.Period1StartingTime);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume);

        var orderLine2 = new CreateOrderLineDto
        {
            ProductId    = BookingTestConsts.BookingProduct1Id,
            ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id,
            Quantity     = 1
        };

        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId,
                               BookingTestConsts.PeriodScheme1Id);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingAssetCategoryId,
                               BookingTestConsts.AssetCategory1Id);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime,
                               BookingTestConsts.Period1StartingTime);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume);

        var order = await orderAppService.CreateAsync(new CreateOrderDto
        {
            StoreId    = BookingTestConsts.Store1Id,
            OrderLines = new List <CreateOrderLineDto>
            {
                orderLine1, orderLine2
            }
        });

        order.ActualTotalPrice.ShouldBe(15m);
    }
示例#8
0
    public virtual async Task <Money?> GetUnitPriceOrNullAsync(CreateOrderDto input, CreateOrderLineDto inputOrderLine,
                                                               ProductDto product, ProductSkuDto productSku, Currency effectiveCurrency)
    {
        if (inputOrderLine.FindBookingAssetId() is not null)
        {
            return(await GetAssetBookingUnitPriceAsync(input, inputOrderLine, effectiveCurrency));
        }

        if (inputOrderLine.FindBookingAssetCategoryId() is not null)
        {
            return(await GetAssetCategoryBookingUnitPriceAsync(input, inputOrderLine, effectiveCurrency));
        }

        return(null);
    }
示例#9
0
        protected virtual async Task <Money> GetUnitPriceAsync(CreateOrderDto input, CreateOrderLineDto inputOrderLine,
                                                               ProductDto product, ProductSkuDto productSku, Currency effectiveCurrency)
        {
            foreach (var overrider in _orderLinePriceOverriders)
            {
                var overridenUnitPrice =
                    await overrider.GetUnitPriceOrNullAsync(input, inputOrderLine, product, productSku,
                                                            effectiveCurrency);

                if (overridenUnitPrice is not null)
                {
                    return(overridenUnitPrice.Value);
                }
            }

            return(new Money(productSku.Price, effectiveCurrency));
        }
示例#10
0
        protected virtual async Task <OrderLine> GenerateNewOrderLineAsync(CreateOrderLineDto input, Dictionary <Guid, ProductDto> productDict)
        {
            var product    = productDict[input.ProductId];
            var productSku = product.ProductSkus.Single(x => x.Id == input.ProductSkuId);

            return(new OrderLine(
                       id: _guidGenerator.Create(),
                       productId: product.Id,
                       productSkuId: productSku.Id,
                       productModificationTime: product.LastModificationTime ?? product.CreationTime,
                       productDetailModificationTime: productSku.LastModificationTime ?? productSku.CreationTime,
                       productName: product.DisplayName,
                       skuDescription: await GenerateSkuDescriptionAsync(product, productSku),
                       mediaResources: product.MediaResources,
                       currency: productSku.Currency,
                       unitPrice: productSku.Price,
                       totalPrice: productSku.Price * input.Quantity,
                       totalDiscount: 0,
                       quantity: input.Quantity
                       ));
        }
示例#11
0
        public IActionResult AddOrderLineToOrder(long orderId, [FromBody] CreateOrderLineDto createOrderLineDto)
        {
            try
            {
                Order order = _unitOfWork.Orders.Get(orderId);

                if (order == null)
                {
                    return(BadRequest("Order Not Found"));
                }

                Item item = _unitOfWork.Items.Get(createOrderLineDto.ItemId);

                if (item == null)
                {
                    return(BadRequest("Item Not Found"));
                }

                Result <Quantity> quantityOrError = Quantity.Create(createOrderLineDto.Quantity);
                Result <Tax>      taxOrError      = Tax.Create(createOrderLineDto.Tax);

                Result result = Result.Combine(quantityOrError, taxOrError);
                if (result.IsFailure)
                {
                    return(BadRequest(result.Error));
                }

                order.AddOrderLine(createOrderLineDto.Note, quantityOrError.Value, taxOrError.Value, item, order);

                _unitOfWork.Orders.Add(order);
                _unitOfWork.Complete();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        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);
        }
示例#13
0
 public static TimeSpan GetBookingDuration(this CreateOrderLineDto orderLine)
 {
     return(Check.NotNull(FindBookingDuration(orderLine),
                          BookingOrderProperties.OrderLineBookingDuration) !.Value);
 }
示例#14
0
 public static Guid?FindBookingAssetId(this CreateOrderLineDto orderLine)
 {
     return(orderLine.GetProperty <Guid?>(BookingOrderProperties.OrderLineBookingAssetId));
 }
示例#15
0
 public static TimeSpan?FindBookingDuration(this CreateOrderLineDto orderLine)
 {
     return(orderLine.FindTimeSpanProperty(BookingOrderProperties.OrderLineBookingDuration));
 }
示例#16
0
 public static DateTime GetBookingDate(this CreateOrderLineDto orderLine)
 {
     return(Check.NotNull(FindBookingDate(orderLine),
                          BookingOrderProperties.OrderLineBookingDate) !.Value);
 }
示例#17
0
 public static DateTime?FindBookingDate(this CreateOrderLineDto orderLine)
 {
     return(orderLine.FindDateTimeProperty(BookingOrderProperties.OrderLineBookingDate));
 }
示例#18
0
 public static int?FindBookingVolume(this CreateOrderLineDto orderLine)
 {
     return(orderLine.Quantity);
 }
示例#19
0
 public static Guid GetBookingPeriodId(this CreateOrderLineDto orderLine)
 {
     return(Check.NotNull(FindBookingPeriodId(orderLine),
                          BookingOrderProperties.OrderLineBookingPeriodId) !.Value);
 }
    private Task <AuthorizationHandlerContext> CreateAuthorizationHandlerContextAsync()
    {
        var orderLine1 = new CreateOrderLineDto
        {
            ProductId    = BookingTestConsts.BookingProduct1Id,
            ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id,
            Quantity     = 1
        };

        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId,
                               BookingTestConsts.PeriodScheme1Id);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingAssetId, BookingTestConsts.Asset1Id);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime,
                               BookingTestConsts.Period1StartingTime);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration);
        orderLine1.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume);

        var orderLine2 = new CreateOrderLineDto
        {
            ProductId    = BookingTestConsts.BookingProduct1Id,
            ProductSkuId = BookingTestConsts.BookingProduct1Sku1Id,
            Quantity     = 1
        };

        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodSchemeId,
                               BookingTestConsts.PeriodScheme1Id);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingPeriodId, BookingTestConsts.Period1Id);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingAssetCategoryId,
                               BookingTestConsts.AssetCategory1Id);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDate, BookingTestConsts.BookingDate);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingStartingTime,
                               BookingTestConsts.Period1StartingTime);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingDuration, BookingTestConsts.Period1Duration);
        orderLine2.SetProperty(BookingOrderProperties.OrderLineBookingVolume, BookingTestConsts.Volume);

        var currentPrincipalAccessor = ServiceProvider.GetRequiredService <ICurrentPrincipalAccessor>();

        return(Task.FromResult(new AuthorizationHandlerContext(
                                   new[] { new OrderOperationAuthorizationRequirement(OrderOperation.Creation) },
                                   currentPrincipalAccessor.Principal,
                                   new OrderCreationResource
        {
            Input = new CreateOrderDto
            {
                StoreId = BookingTestConsts.Store1Id,
                OrderLines = new List <CreateOrderLineDto>
                {
                    orderLine1, orderLine2
                }
            },
            ProductDictionary = new Dictionary <Guid, ProductDto>
            {
                {
                    BookingTestConsts.BookingProduct1Id,
                    new ProductDto
                    {
                        Id = BookingTestConsts.BookingProduct1Id,
                        StoreId = BookingTestConsts.Store1Id,
                        ProductGroupName = BookingTestConsts.BookingProductGroupName
                    }
                }
            }
        })));
    }
 protected virtual OccupyAssetByCategoryInfoModel CreateOccupyAssetByCategoryInfoModel(Guid assetCategoryId,
                                                                                       CreateOrderLineDto orderLine)
 {
     return(new OccupyAssetByCategoryInfoModel(
                assetCategoryId,
                orderLine.GetBookingVolume(),
                orderLine.GetBookingDate(),
                orderLine.GetBookingStartingTime(),
                orderLine.GetBookingDuration()
                ));
 }