Exemple #1
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <OrderDto> CreateAsync(OrderCreationDto input)
        {
            var productIds = input.Items.Select(x => x.ProductId).ToArray();

            //获取产品的价格,名字
            var rpcResult = await _warehouseRpc.GetProductsAsync(new ProductSearchListRto { Ids = productIds });

            if (!rpcResult.IsSuccessStatusCode)
            {
                var apiError = ((Refit.ValidationApiException)rpcResult.Error).Content;
                throw new BusinessException(rpcResult.StatusCode, apiError.Detail);
            }

            var orderId = IdGenerater.GetNextId(IdGenerater.DatacenterId, IdGenerater.WorkerId);

            var items = from o in input.Items
                        join p in rpcResult.Content on o.ProductId equals p.Id
                        select(new OrderItemProduct(p.Id.ToLong().Value, p.Name, p.Price), o.Count);

            //需要发布领域事件,订单中心订阅该事件
            var order = await _orderMgr.CreateAsync(orderId
                                                    ,
                                                    input.CustomerId
                                                    ,
                                                    items
                                                    ,
                                                    new OrderReceiver(input.DeliveryInfomaton?.Name, input.DeliveryInfomaton?.Phone, input.DeliveryInfomaton?.Address)
                                                    );

            await _orderRepo.InsertAsync(order);

            return(_mapper.Map <OrderDto>(order));
        }
Exemple #2
0
    /// <summary>
    /// 创建订单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task <OrderDto> CreateAsync(OrderCreationDto input)
    {
        var productIds = input.Items.Select(x => x.ProductId).ToArray();
        //调用whse服务获取产品的价格,名字
        var restRpcResult = await _whseRestClient.GetProductsAsync(new ProductSearchListRto { Ids = productIds });

        Guard.Checker.ThrowIf(() => (!restRpcResult.IsSuccessStatusCode || restRpcResult.Content.IsNullOrEmpty()), "product is not extists");
        var products = restRpcResult.Content;
        var orderId  = IdGenerater.GetNextId();
        var items    = from o in input.Items
                       join p in products on o.ProductId equals p.Id
                       select(new OrderItemProduct(p.Id, p.Name, p.Price), o.Count);

        //需要发布领域事件,通知仓储中心冻结库存
        var order = await _orderMgr.CreateAsync
                        (orderId
                        , input.CustomerId
                        , items
                        , new OrderReceiver(input.DeliveryInfomaton?.Name, input.DeliveryInfomaton?.Phone, input.DeliveryInfomaton?.Address)
                        );

        // 保存到数据库
        await _orderRepo.InsertAsync(order);

        return(Mapper.Map <OrderDto>(order));
    }
 public Order ToDomain(OrderCreationDto orderCreationDto)
 {
     return(Order.OrderBuilder.Order()
            .WithCustomerId(new Guid(orderCreationDto.CustomerId))
            .WithOrderItems(orderCreationDto.ItemGroups.Select(group => _orderItemMapper.ToDomain(group)))
            .Build());
 }
Exemple #4
0
        public async Task <ResultDto <OrderCreationMessageResponseDto> > Create(OrderCreationDto order)
        {
            Console.WriteLine("called controller");

            using (_orderCreationMessageSender)
                return(await _orderCreationMessageSender.CallAsync(order));
        }
        public IActionResult Create([FromBody] OrderCreationDto order)
        {
            try {
                if (order == null)
                {
                    return(BadRequest("Order object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                var orderEntity = _mapper.Map <Order>(order);

                _repository.Order.Create(orderEntity);
                _repository.Save();

                var createdOrder = _mapper.Map <OrderDto>(orderEntity);

                return(CreatedAtRoute("OrderById", new {
                    id = createdOrder.Id
                }, createdOrder));
            } catch (Exception ex) {
                return(StatusCode(500, "Internal server error"));
            }
        }
Exemple #6
0
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <OrderDto> CreateAsync(OrderCreationDto input)
        {
            var productIds = input.Items.Select(x => x.ProductId).ToArray();

            //获取产品的价格,名字
            var rpcResult = await _warehouseRpc.GetListAsync(productIds);

            if (!rpcResult.IsSuccessStatusCode)
            {
                throw new AdncException(rpcResult.StatusCode, "");
            }

            var orderId = IdGenerater.GetNextId(IdGenerater.DatacenterId, IdGenerater.WorkerId);

            var items = from o in input.Items
                        join p in rpcResult.Content on o.ProductId equals p.Id
                        select(new OrderItemProduct(p.Id.ToLong().Value, p.Name, p.Price), o.Count);

            var order = await _orderMgr.CreateAsync(orderId
                                                    ,
                                                    input.CustomerId
                                                    ,
                                                    items
                                                    ,
                                                    new OrderDeliveryInfomation(input.DeliveryInfomaton?.Name, input.DeliveryInfomaton?.Phone, input.DeliveryInfomaton?.Address)
                                                    );

            return(_mapper.Map <OrderDto>(order));
        }
Exemple #7
0
        private async Task <Guid> Test_CreateOrder(Guid productId)
        {
            OrderCreationDto orderCreation = new OrderCreationDto()
            {
                Delivery = new DeliveryDto()
                {
                    City    = "city",
                    Country = "country",
                    Street  = "street"
                },
                Products = new List <ProductQuantityDto>()
                {
                    new ProductQuantityDto()
                    {
                        ProductId = productId,
                        Quantity  = 1
                    }
                }
            };

            using var orderCreationConsumer = _serviceProvider.GetService <OrderCreationConsumer>();
            await orderCreationConsumer.StartAsync(CancellationToken.None);

            ResultDto <OrderCreationMessageResponseDto> result = await _controller.Create(orderCreation);

            Assert.NotEqual(Guid.NewGuid(), result.Result.OrderId);

            return(result.Result.OrderId);
        }
        public async Task <IActionResult> CreateOrder([FromBody] OrderCreationDto orderDto)
        {
            string email = User.Identity.Name;

            if (email == null)
            {
                return(Unauthorized());
            }

            await _orderService.CreateOrder(email, orderDto);

            return(Ok());
        }
        public async Task <IActionResult> CreateOrder([FromBody] OrderCreationDto order)
        {
            var orderEntity = _mapper.Map <Order>(order);

            _repository.Order.CreateOrder(orderEntity);
            await _repository.SaveAsync();

            _repository.Order.GenerateOrderNumber(orderEntity);
            await _repository.SaveAsync();

            var createdOrder = _mapper.Map <OrderDto>(orderEntity);

            return(CreatedAtRoute("OrderById", new { id = createdOrder.orderId }, createdOrder));
        }
        public async Task CreateOrderAsync(OrderCreationDto orderCreationDto)
        {
            var order = Mapper.Map <Order>(orderCreationDto);

            foreach (var dishId in orderCreationDto.Dishes)
            {
                var dish = await _dishesRepository.GetByIdAsync(dishId);

                order.Dishes.Add(new OrderDish {
                    Dish = dish
                });
            }
            await _ordersRepository.AddAsync(order);

            await UnitOfWork.CommitAsync();

            _eventsManager.EnqueueEvent(new OrderCreatedEvent());
        }
Exemple #11
0
        public async Task <IActionResult> CreateOrder([FromBody] OrderCreationDto orderDto)
        {
            if (orderDto == null)
            {
                _Logger.LogError("order is empty");
                return(BadRequest());
            }


            try
            {
                //gets phone number and address from claims of the currently logged in user
                ClaimsPrincipal customer    = this.User;
                var             phoneNumber = customer.Claims.Where(c => c.Type == "PhoneNumber")
                                              .Select(c => c.Value).FirstOrDefault();

                var Address = customer.Claims.Where(c => c.Type == "Address")
                              .Select(c => c.Value).FirstOrDefault();

                var order = _mapper.Map <Order>(orderDto);

                order.phone           = phoneNumber;
                order.ShippingAddress = Address;


                _repository.Orders.CreateOrder(order);

                await _repository.SaveAsync();


                var orderCreated = _mapper.Map <OrderDto>(order);

                return(CreatedAtRoute("OrderByNumber", new { orderNumber = order.OrderNumber }, orderCreated));
            }
            catch (Exception ex)
            {
                _Logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }
        public async Task CreateOrder(string email, OrderCreationDto orderDto)
        {
            var user = await _userManager.FindByEmailAsync(email);

            using (IUnitOfWork unitOfWork = _unitOfWorkFactory.Create())
            {
                IRepository <Auto> autos = unitOfWork.Repository <Auto>();
                var auto = autos.Find(x => x.AutoRiaId == orderDto.AutoRiaId);
                if (auto == null)
                {
                    auto = new Auto
                    {
                        AutoRiaId = orderDto.AutoRiaId,
                        MarkName  = orderDto.MarkName,
                        ModelName = orderDto.ModelName,
                        Year      = orderDto.Year,
                        City      = orderDto.City,
                        PhotoLink = orderDto.PhotoLink,
                        TypeId    = orderDto.CategoryId,
                        MarkId    = orderDto.MarkId,
                        ModelId   = orderDto.ModelId
                    };
                    autos.Add(auto);
                }

                IRepository <Order> order = unitOfWork.Repository <Order>();
                order.Add(new Order
                {
                    CustomerId  = user.Id,
                    AutoId      = auto.Id,
                    Description = orderDto.Description,
                    Date        = DateTime.Now.ToUniversalTime()
                });

                unitOfWork.Save();
            }
        }
 public OrderAfterCreationDto CreateOrder([FromBody] OrderCreationDto orderDto)
 {
     return(_orderMapper.ToOrderAfterCreationDto(
                _orderService.CreateOrder(
                    _orderMapper.ToDomain(orderDto))));
 }
Exemple #14
0
 public async Task <ActionResult <OrderDto> > CreateAsync([FromBody] OrderCreationDto input)
 {
     return(await _orderSrv.CreateAsync(input));
 }
        public async Task <IActionResult> Post(OrderCreationDto orderCreationDto)
        {
            await _ordersService.CreateOrderAsync(orderCreationDto);

            return(Ok());
        }