public async Task <OrderViewModel> Handle(CancelOrderCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderRepository.GetOrderbyDealIdAsync(request.DealId);

            if (order == null)
            {
                throw new ClientException("操作失败", new List <string> {
                    $"No order for deal id {request.DealId}."
                });
            }

            var processingUserId = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (processingUserId != order.User1Id && processingUserId != order.User2Id)
            {
                throw new ClientException("操作失败", new List <string> {
                    $"Order does not belong to user {order.User1Id} and user {order.User2Id}."
                });
            }

            order.Cancel(request.Description);

            if (await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken))
            {
                var anotherUserId = processingUserId == order.User1Id ? order.User2Id : order.User1Id;
                await SendOrderCanceledEventAsync(processingUserId, anotherUserId, request.DealId, order.Id, request.Description);
            }

            return(await _orderQueries.GetOrderAsync(order.Id));
        }
        public async Task <OrderViewModel> Handle(UploadOriginalCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderRepository.GetOrderWithAttachmentsAsync(request.OrderId);

            order.UploadOriginalFiles(request.Attachments);
            await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            return(await _orderQueries.GetOrderAsync(order.Id));
        }
        public async Task <OrderViewModel> Handle(ConfirmShotCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderRepository.GetByIdAsync(request.OrderId);

            order.ConfirmShot();
            await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            return(await _orderQueries.GetOrderAsync(order.Id));
        }
        public async Task <OrderViewModel> Handle(CheckProcessedCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderRepository.GetByIdAsync(request.OrderId);

            order.AcceptProcessedFiles();
            if (await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken))
            {
                await SendOrderFinishedEventAsync(order.User1Id, order.User2Id);

                return(await _orderQueries.GetOrderAsync(order.Id));
            }
            throw new ApplicationException("操作失败");
        }
        public async Task <ActionResult> GetOrderAsync(int orderId)
        {
            try
            {
                var order = await _orderQueries.GetOrderAsync(orderId);

                return(Ok(order));
            }
            catch
            {
                return(NotFound());
            }
        }
        public async Task <ActionResult> GetOrderAsync(int orderId)
        {
            try
            {
                //var order customer = await _mediator.Send(new GetOrderByIdQuery(orderId));
                var order = await _orderQueries.GetOrderAsync(orderId);

                return(Ok(order));
            }
            catch
            {
                return(NotFound());
            }
        }
Beispiel #7
0
        public async Task <ActionResult> GetOrderAsync(int orderId)
        {
            try
            {
                //Todo: It's good idea to take advantage of GetOrderByIdQuery and handle by GetCustomerByIdQueryHandler
                //var order customer = await _mediator.Send(new GetOrderByIdQuery(orderId));
                var order = await _orderQueries.GetOrderAsync(orderId);

                return(Ok(order));
            }
            catch
            {
                return(NotFound());
            }
        }
        public async Task <OrderViewModel> Handle(AcceptOrderCommand request, CancellationToken cancellationToken)
        {
            var order = await _orderRepository.GetOrderbyDealIdAsync(request.DealId);

            if (order == null)
            {
                throw new ClientException("操作失败", new List <string> {
                    $"No order for deal id {request.DealId}."
                });
            }

            order.Accept();

            if (await _orderRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken))
            {
                var userId = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
                await SendOrderAcceptedEventAsync(userId, order.User1Id == userId?order.User2Id : order.User1Id, request.DealId);
            }

            return(await _orderQueries.GetOrderAsync(order.Id));
        }
 public Task <Order> GetOrderAsync(int orderId) =>
 _orderQueries.GetOrderAsync(orderId);
Beispiel #10
0
        public async Task <ActionResult> GetOrderAsync(int orderId)
        {
            var order = await _orderQueries.GetOrderAsync(orderId);

            return(Ok(order));
        }
Beispiel #11
0
        public async Task <ActionResult <IEnumerable <OrderViewModel> > > GetOrderAsync(Guid orderId)
        {
            var order = await _orderQueries.GetOrderAsync(orderId);

            return(Ok(ResponseWrapper.CreateOkResponseWrapper(order)));
        }
        public async Task <OrderSummeryViewModel> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
        {
            var orderSummeryViewModel = await OrderQueries.GetOrderAsync(request.OrderId);

            return(orderSummeryViewModel);
        }
Beispiel #13
0
 public async Task <OrderViewModel> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
 {
     return(await _orderQueries.GetOrderAsync(request.OrderId));
 }
        public async Task <Order> Get(int orderId)
        {
            var order = await _orderQueries.GetOrderAsync(orderId);

            return(order);
        }