public ActionResult <OrderItemDto> AddOrderItem(OrderItemForCreationDto orderItemForCreation)
        {
            var orderItem = _mapper.Map <OrderItem>(orderItemForCreation);

            _orderItemRepository.AddOrderItem(orderItem);
            _orderItemRepository.Save();

            var orderItemDto = _mapper.Map <OrderItemDto>(orderItem);

            return(CreatedAtRoute("GetOrderItem",
                                  new { orderItemDto.OrderItemId },
                                  orderItemDto));
        }
예제 #2
0
        public async Task <OrderItem> BuildOrderItem(OrderItemForCreationDto orderItemDto)
        {
            var orderItem = new OrderItem();

            orderItem.DateFrom        = orderItemDto.DateFrom;
            orderItem.DateTo          = orderItemDto.DateTo;
            orderItem.TotalPrice      = orderItemDto.TotalPrice;
            orderItem.OrderItemAssets = new List <OrderItemAsset>();
            var availableAssets = await _assetAvailabilityService
                                  .GetAvailableAssetsByProductId(orderItemDto.ProductId, orderItemDto.AssetsCount,
                                                                 orderItemDto.DateFrom, orderItemDto.DateTo);

            foreach (var asset in availableAssets)
            {
                OrderItemAsset orderItemAsset = new OrderItemAsset();
                orderItemAsset.AssetId     = asset.Id;
                orderItemAsset.OrderItemId = orderItem.Id;
                orderItem.OrderItemAssets.Add(orderItemAsset);
            }
            return(orderItem);
        }