コード例 #1
0
        public async Task <bool> Handle(DeleteOrderCommand request, CancellationToken cancellationToken)
        {
            if (request.Order == null)
            {
                throw new ArgumentNullException(nameof(request.Order));
            }

            var shipments = await _shipmentService.GetShipmentsByOrder(request.Order.Id);

            if (shipments.Any())
            {
                throw new Exception("Cannot do delete for order with shipments");
            }

            //check whether the order wasn't cancelled before
            if (request.Order.OrderStatusId != (int)OrderStatusSystem.Cancelled)
            {
                //return (add) back redeemded loyalty points
                await _mediator.Send(new ReturnBackRedeemedLoyaltyPointsCommand()
                {
                    Order = request.Order
                });

                //reduce (cancel) back loyalty points (previously awarded for this order)
                await _mediator.Send(new ReduceLoyaltyPointsCommand()
                {
                    Order = request.Order
                });

                //Adjust inventory
                foreach (var orderItem in request.Order.OrderItems)
                {
                    var product = await _productService.GetProductById(orderItem.ProductId);

                    if (product != null)
                    {
                        await _inventoryManageService.AdjustReserved(product, orderItem.Quantity - orderItem.CancelQty, orderItem.Attributes, orderItem.WarehouseId);
                    }
                }

                //cancel reservations
                await _productReservationService.CancelReservationsByOrderId(request.Order.Id);

                //cancel bid
                await _auctionService.CancelBidByOrder(request.Order.Id);
            }

            //deactivate gift vouchers
            if (_orderSettings.DeactivateGiftVouchersAfterDeletingOrder)
            {
                await _mediator.Send(new ActivatedValueForPurchasedGiftVouchersCommand()
                {
                    Order = request.Order, Activate = false
                });
            }

            request.Order.Deleted = true;
            //now delete an order
            await _orderService.UpdateOrder(request.Order);

            //cancel discounts
            await _discountService.CancelDiscount(request.Order.Id);

            //add a note
            await _orderService.InsertOrderNote(new OrderNote
            {
                Note = $"Order has been deleted",
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow,
                OrderId           = request.Order.Id,
            });

            //event notification
            await _mediator.Publish(new OrderDeletedEvent(request.Order));

            return(true);
        }
コード例 #2
0
        public async Task <bool> Handle(CancelOrderCommand request, CancellationToken cancellationToken)
        {
            if (request.Order == null)
            {
                throw new ArgumentNullException(nameof(request.Order));
            }

            if (request.Order.OrderStatusId == (int)OrderStatusSystem.Cancelled)
            {
                throw new Exception("Cannot do cancel for order.");
            }

            var shipments = await _shipmentService.GetShipmentsByOrder(request.Order.Id);

            if (shipments.Any())
            {
                throw new Exception("Cannot do cancel for order with shipments");
            }

            //Cancel order
            await _mediator.Send(new SetOrderStatusCommand()
            {
                Order            = request.Order,
                Os               = OrderStatusSystem.Cancelled,
                NotifyCustomer   = request.NotifyCustomer,
                NotifyStoreOwner = request.NotifyStoreOwner
            });

            //add a note
            await _orderService.InsertOrderNote(new OrderNote
            {
                Note = "Order has been cancelled",
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow,
                OrderId           = request.Order.Id,
            });

            //return (add) back redeemded loyalty points
            await _mediator.Send(new ReturnBackRedeemedLoyaltyPointsCommand()
            {
                Order = request.Order
            });

            //Adjust inventory
            foreach (var orderItem in request.Order.OrderItems)
            {
                var product = await _productService.GetProductById(orderItem.ProductId);

                await _inventoryManageService.AdjustReserved(product, orderItem.Quantity - orderItem.CancelQty, orderItem.Attributes, orderItem.WarehouseId);
            }
            //update open qty
            foreach (var orderItem in request.Order.OrderItems)
            {
                orderItem.OpenQty = 0;
            }

            await _orderService.UpdateOrder(request.Order);

            //cancel reservations
            await _productReservationService.CancelReservationsByOrderId(request.Order.Id);

            //cancel bid
            await _auctionService.CancelBidByOrder(request.Order.Id);

            //cancel discount
            await _discountService.CancelDiscount(request.Order.Id);

            //cancel payments
            var payment = await _paymentTransactionService.GetByOrdeGuid(request.Order.OrderGuid);

            if (payment != null)
            {
                await _paymentService.CancelPayment(payment);
            }

            //event notification
            await _mediator.Publish(new OrderCancelledEvent(request.Order));

            return(true);
        }
コード例 #3
0
        public async Task <bool> Handle(DeleteOrderCommand request, CancellationToken cancellationToken)
        {
            if (request.Order == null)
            {
                throw new ArgumentNullException("order");
            }

            //check whether the order wasn't cancelled before
            //if it already was cancelled, then there's no need to make the following adjustments
            //(such as reward points, inventory, recurring payments)
            //they already was done when cancelling the order
            if (request.Order.OrderStatus != OrderStatus.Cancelled)
            {
                //return (add) back redeemded reward points
                await _mediator.Send(new ReturnBackRedeemedRewardPointsCommand()
                {
                    Order = request.Order
                });

                //reduce (cancel) back reward points (previously awarded for this order)
                await _mediator.Send(new ReduceRewardPointsCommand()
                {
                    Order = request.Order
                });

                //cancel recurring payments
                var recurringPayments = await _orderService.SearchRecurringPayments(initialOrderId : request.Order.Id);

                foreach (var rp in recurringPayments)
                {
                    var errors = await _mediator.Send(new CancelRecurringPaymentCommand()
                    {
                        RecurringPayment = rp
                    });

                    //use "errors" variable?
                }

                //Adjust inventory for already shipped shipments
                //only products with "use multiple warehouses"
                foreach (var shipment in await _shipmentService.GetShipmentsByOrder(request.Order.Id))
                {
                    foreach (var shipmentItem in shipment.ShipmentItems)
                    {
                        var product = await _productService.GetProductById(shipmentItem.ProductId);

                        shipmentItem.ShipmentId = shipment.Id;
                        if (product != null)
                        {
                            await _productService.ReverseBookedInventory(product, shipment, shipmentItem);
                        }
                    }
                }
                //Adjust inventory
                foreach (var orderItem in request.Order.OrderItems)
                {
                    var product = await _productService.GetProductById(orderItem.ProductId);

                    if (product != null)
                    {
                        await _productService.AdjustInventory(product, orderItem.Quantity, orderItem.AttributesXml, orderItem.WarehouseId);
                    }
                }

                //cancel reservations
                await _productReservationService.CancelReservationsByOrderId(request.Order.Id);

                //cancel bid
                await _auctionService.CancelBidByOrder(request.Order.Id);
            }

            //deactivate gift cards
            if (_orderSettings.DeactivateGiftCardsAfterDeletingOrder)
            {
                await _mediator.Send(new ActivatedValueForPurchasedGiftCardsCommand()
                {
                    Order = request.Order, Activate = false
                });
            }

            request.Order.Deleted = true;
            //now delete an order
            await _orderService.UpdateOrder(request.Order);

            //cancel discounts
            await _discountService.CancelDiscount(request.Order.Id);

            return(true);
        }
コード例 #4
0
        public async Task <bool> Handle(CancelOrderCommand request, CancellationToken cancellationToken)
        {
            if (request.Order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (request.Order.OrderStatus == OrderStatus.Cancelled)
            {
                throw new Exception("Cannot do cancel for order.");
            }

            //Cancel order
            await _mediator.Send(new SetOrderStatusCommand()
            {
                Order            = request.Order,
                Os               = OrderStatus.Cancelled,
                NotifyCustomer   = request.NotifyCustomer,
                NotifyStoreOwner = request.NotifyStoreOwner
            });

            //add a note
            await _orderService.InsertOrderNote(new OrderNote {
                Note = "Order has been cancelled",
                DisplayToCustomer = false,
                CreatedOnUtc      = DateTime.UtcNow,
                OrderId           = request.Order.Id,
            });

            //return (add) back redeemded reward points
            await _mediator.Send(new ReturnBackRedeemedRewardPointsCommand()
            {
                Order = request.Order
            });

            //cancel recurring payments
            var recurringPayments = await _orderService.SearchRecurringPayments(initialOrderId : request.Order.Id);

            foreach (var rp in recurringPayments)
            {
                var errors = await _mediator.Send(new CancelRecurringPaymentCommand()
                {
                    RecurringPayment = rp
                });
            }

            //Adjust inventory for already shipped shipments
            //only products with "use multiple warehouses"
            var shipments = await _shipmentService.GetShipmentsByOrder(request.Order.Id);

            foreach (var shipment in shipments)
            {
                foreach (var shipmentItem in shipment.ShipmentItems)
                {
                    var product = await _productService.GetProductById(shipmentItem.ProductId);

                    shipmentItem.ShipmentId = shipment.Id;
                    await _productService.ReverseBookedInventory(product, shipment, shipmentItem);
                }
            }
            //Adjust inventory
            foreach (var orderItem in request.Order.OrderItems)
            {
                var product = await _productService.GetProductById(orderItem.ProductId);

                await _productService.AdjustInventory(product, orderItem.Quantity, orderItem.AttributesXml, orderItem.WarehouseId);
            }

            //cancel reservations
            await _productReservationService.CancelReservationsByOrderId(request.Order.Id);

            //cancel bid
            await _auctionService.CancelBidByOrder(request.Order.Id);

            //cancel discount
            await _discountService.CancelDiscount(request.Order.Id);

            //event notification
            await _mediator.Publish(new OrderCancelledEvent(request.Order));

            return(true);
        }