示例#1
0
        public async Task <JsonResponse> Create(OrderInfoRequestDto orderInfoRequestDto)
        {
            orderInfoRequestDto.ToLoginUser();
            List <GoodsQueryDto> goodsQuerys = await GetGoodsAsync(orderInfoRequestDto);

            List <OrderDetailRequestDto> orderDetailRequestDtos = new List <OrderDetailRequestDto>();

            orderInfoRequestDto.Id = Guid.NewGuid().ToString();
            foreach (var item in goodsQuerys)
            {
                var good = orderInfoRequestDto.GoodsRequests.Where(g => g.GoodsId == item.Id).SingleOrDefault();
                orderDetailRequestDtos.Add(new OrderDetailRequestDto()
                {
                    Id      = Guid.NewGuid().ToString(),
                    GoodsId = item.Id,
                    OrderId = orderInfoRequestDto.Id,
                    Count   = good.Count,
                    Price   = item.Price,
                    Money   = good.Count * item.Price
                });
            }
            orderInfoRequestDto.OrderNumber = DateTime.Now.ToString();
            orderInfoRequestDto.TotalMoney  = orderDetailRequestDtos.Select(d => d.Money).Sum();
            orderInfoRequestDto.ExpireTime  = DateTime.Now.AddDays(14);

            var resJson = await new ApplicationEnginee().TryTransactionAsync(async() =>
            {
                await _orderAppService.CreateAsync(orderInfoRequestDto);
                await _orderDetailAppService.BatchCreateAsync(orderDetailRequestDtos);
            });

            return(resJson);
        }
        public async Task <IActionResult> OnPostAsync()
        {
            var dto = ObjectMapper.Map <CreateEditOrderViewModel, CreateUpdateOrderDto>(ViewModel);
            await _service.CreateAsync(dto);

            return(NoContent());
        }
示例#3
0
        public async Task <ActionResult> CreateAsync([FromBody] CreateOrderRequestModel createOrderRequestModel)
        {
            const string actionName = nameof(CreateAsync);

            Logger.LogDebug(LoggingMessage.ProcessingRequestWithModel, actionName, createOrderRequestModel);
            var response = await _orderAppService.CreateAsync(createOrderRequestModel);

            Logger.LogInfomation(LoggingMessage.RequestResults, actionName);

            return(Ok(response));
        }
示例#4
0
 public Task <OrderDto> CreateAsync(CreateOrderDto input)
 {
     return(_service.CreateAsync(input));
 }
示例#5
0
 public async Task <ActionResult <OrderDto> > CreateAsync([FromBody] OrderCreationDto input)
 {
     return(await _orderSrv.CreateAsync(input));
 }
示例#6
0
        public async Task Order_Should_Be_Created()
        {
            // Arrange
            var createOrderDto = new CreateOrderDto
            {
                CustomerRemark = "customer remark",
                StoreId        = OrderTestData.Store1Id,
                OrderLines     = new List <CreateOrderLineDto>
                {
                    new CreateOrderLineDto
                    {
                        ProductId    = OrderTestData.Product1Id,
                        ProductSkuId = OrderTestData.ProductSku1Id,
                        Quantity     = 10
                    }
                }
            };

            // Act
            var createResponse = await _orderAppService.CreateAsync(createOrderDto);

            var response = await _orderAppService.GetAsync(createResponse.Id);

            // Assert
            response.ShouldNotBeNull();
            response.Currency.ShouldBe("CNY");
            response.CanceledTime.ShouldBeNull();
            response.CancellationReason.ShouldBeNullOrEmpty();
            response.CompletionTime.ShouldBeNull();
            response.CustomerRemark.ShouldBe("customer remark");
            response.OrderNumber.ShouldNotBeNull();
            response.OrderStatus.ShouldBe(OrderStatus.Pending);
            response.PaidTime.ShouldBeNull();
            response.PaymentId.ShouldBeNull();
            response.RefundAmount.ShouldBe(0m);
            response.StaffRemark.ShouldBeNullOrEmpty();
            response.StoreId.ShouldBe(OrderTestData.Store1Id);
            response.TotalDiscount.ShouldBe(0m);
            response.TotalPrice.ShouldBe(10m);
            response.ActualTotalPrice.ShouldBe(10m);
            response.CustomerUserId.ShouldBe(Guid.Parse("2e701e62-0953-4dd3-910b-dc6cc93ccb0d"));
            response.ProductTotalPrice.ShouldBe(10m);
            response.ReducedInventoryAfterPaymentTime.ShouldBeNull();
            response.ReducedInventoryAfterPlacingTime.ShouldNotBeNull();
            response.OrderLines.Count.ShouldBe(1);

            var responseOrderLine = response.OrderLines.First();

            responseOrderLine.ProductId.ShouldBe(OrderTestData.Product1Id);
            responseOrderLine.ProductSkuId.ShouldBe(OrderTestData.ProductSku1Id);
            responseOrderLine.ProductDisplayName.ShouldBe("Hello pencil");
            responseOrderLine.ProductUniqueName.ShouldBe("Pencil");
            responseOrderLine.ProductGroupName.ShouldBe("Default");
            responseOrderLine.ProductGroupDisplayName.ShouldBe("Default");
            responseOrderLine.SkuName.ShouldBe("My SKU");
            responseOrderLine.UnitPrice.ShouldBe(1m);
            responseOrderLine.TotalPrice.ShouldBe(10m);
            responseOrderLine.TotalDiscount.ShouldBe(0m);
            responseOrderLine.ActualTotalPrice.ShouldBe(10m);
            responseOrderLine.Currency.ShouldBe("CNY");
            responseOrderLine.Quantity.ShouldBe(10);
            responseOrderLine.ProductModificationTime.ShouldBe(OrderTestData.ProductLastModificationTime);
            responseOrderLine.RefundAmount.ShouldBe(0m);
            responseOrderLine.RefundedQuantity.ShouldBe(0);

            UsingDbContext(context =>
            {
                context.Orders.Count().ShouldBe(1);
                var order = context.Orders.Include(x => x.OrderLines).First();
                order.ShouldNotBeNull();
                order.Currency.ShouldBe("CNY");
                order.CanceledTime.ShouldBeNull();
                order.CancellationReason.ShouldBeNullOrEmpty();
                order.CompletionTime.ShouldBeNull();
                order.CustomerRemark.ShouldBe("customer remark");
                order.OrderNumber.ShouldNotBeNull();
                order.OrderStatus.ShouldBe(OrderStatus.Pending);
                order.PaidTime.ShouldBeNull();
                order.PaymentId.ShouldBeNull();
                order.RefundAmount.ShouldBe(0m);
                order.StaffRemark.ShouldBeNullOrEmpty();
                order.StoreId.ShouldBe(OrderTestData.Store1Id);
                order.TotalDiscount.ShouldBe(0m);
                order.TotalPrice.ShouldBe(10m);
                order.ActualTotalPrice.ShouldBe(10m);
                order.CustomerUserId.ShouldBe(Guid.Parse("2e701e62-0953-4dd3-910b-dc6cc93ccb0d"));
                order.ProductTotalPrice.ShouldBe(10m);
                order.ReducedInventoryAfterPaymentTime.ShouldBeNull();
                order.ReducedInventoryAfterPlacingTime.ShouldNotBeNull();
                order.OrderLines.Count.ShouldBe(1);

                var orderLine = order.OrderLines.First();
                orderLine.ProductId.ShouldBe(OrderTestData.Product1Id);
                orderLine.ProductSkuId.ShouldBe(OrderTestData.ProductSku1Id);
                orderLine.ProductDisplayName.ShouldBe("Hello pencil");
                orderLine.ProductUniqueName.ShouldBe("Pencil");
                orderLine.ProductGroupName.ShouldBe("Default");
                orderLine.ProductGroupDisplayName.ShouldBe("Default");
                orderLine.SkuName.ShouldBe("My SKU");
                orderLine.UnitPrice.ShouldBe(1m);
                orderLine.TotalPrice.ShouldBe(10m);
                orderLine.TotalDiscount.ShouldBe(0m);
                orderLine.ActualTotalPrice.ShouldBe(10m);
                orderLine.Currency.ShouldBe("CNY");
                orderLine.Quantity.ShouldBe(10);
                orderLine.ProductModificationTime.ShouldBe(OrderTestData.ProductLastModificationTime);
                orderLine.RefundAmount.ShouldBe(0m);
                orderLine.RefundedQuantity.ShouldBe(0);
            });
        }
示例#7
0
 public Task <OrderDto> CreateAsync(CreateUpdateOrderDto input)
 {
     return(_orderAppService.CreateAsync(input));
 }