Пример #1
0
        public override async Task<OrderDto> CreateAsync(CreateOrderDto input)
        {
            await CheckCreatePolicyAsync();

            // Todo: Check if the store is open.

            var productDict = await GetProductDictionaryAsync(input.OrderLines.Select(dto => dto.ProductId).ToList(),
                input.StoreId);

            await AuthorizationService.CheckAsync(
                new OrderCreationResource
                {
                    Input = input,
                    ProductDictionary = productDict
                },
                new OrderOperationAuthorizationRequirement(OrderOperation.Creation)
            );

            var order = await _newOrderGenerator.GenerateAsync(CurrentUser.GetId(), input, productDict);

            await DiscountOrderAsync(order, productDict);

            await Repository.InsertAsync(order, autoSave: true);

            return await MapToGetOutputDtoAsync(order);
        }
Пример #2
0
        public override async Task <OrderDto> CreateAsync(CreateOrderDto input)
        {
            await CheckCreatePolicyAsync();

            // Todo: Check if the store is open.

            var productDict = await GetProductDictionaryAsync(input.OrderLines.Select(dto => dto.ProductId).ToList(),
                                                              input.StoreId);

            await _purchasableCheckManager.CheckAsync(input, productDict);

            var order = await _newOrderGenerator.GenerateAsync(input, productDict);

            await _orderDiscountManager.DiscountAsync(order, input.ExtraProperties);

            await Repository.InsertAsync(order, autoSave : true);

            return(MapToGetOutputDto(order));
        }
Пример #3
0
        public override async Task <OrderDto> CreateAsync(CreateOrderDto input)
        {
            // Todo: Check if the store is open.

            var productDict = await GetProductDictionaryAsync(input.OrderLines.Select(dto => dto.ProductId).ToList());

            ThrowIfExistFlashSalesProduct(productDict);

            await AuthorizationService.CheckAsync(
                new OrderCreationResource
            {
                Input             = input,
                ProductDictionary = productDict
            },
                new OrderOperationAuthorizationRequirement(OrderOperation.Creation)
                );

            var productDetailIds = input.OrderLines
                                   .Select(dto =>
                                           productDict[dto.ProductId].GetSkuById(dto.ProductSkuId).ProductDetailId ??
                                           productDict[dto.ProductId].ProductDetailId)
                                   .Where(x => x.HasValue)
                                   .Select(x => x.Value)
                                   .ToList();

            var productDetailDict = await GetProductDetailDictionaryAsync(productDetailIds);

            // Todo: Can we use IProductDataScopedCache/IProductDetailDataScopedCache instead of productDict/productDetailDict?
            var order = await _newOrderGenerator.GenerateAsync(CurrentUser.GetId(), input, productDict, productDetailDict);

            await DiscountOrderAsync(order, productDict);

            await Repository.InsertAsync(order, autoSave : true);

            return(await MapToGetOutputDtoAsync(order));
        }