예제 #1
0
        public IActionResult ShipOrder([ValidOrder] int id)
        {
            var model = new ShipOrderInputModel()
            {
                OrderId = id, Carriers = this.shippingService.GetAllCarriers <CarrierViewModel>()
            };

            return(this.View(model));
        }
예제 #2
0
        public async Task <IActionResult> ShipOrder(ShipOrderInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                var model = new ShipOrderInputModel()
                {
                    OrderId = input.OrderId, Carriers = this.shippingService.GetAllCarriers <CarrierViewModel>()
                };
                return(this.View(model));
            }

            await this.shippingService.ShipOrderAsync(input);

            return(this.RedirectToAction(nameof(this.OrderDetails), new { id = input.OrderId }));
        }
예제 #3
0
        public async Task ShipOrderAsync(ShipOrderInputModel input)
        {
            var order = this.context.Orders.Include(x => x.OrderItems).FirstOrDefault(x => x.Id == input.OrderId);

            if (order.ShippingStatus == ShippingStatus.Shipped)
            {
                return;
            }

            order.ShippingMethod = this.context.ShippingMethods.FirstOrDefault(x => x.Id == input.ShippingMethod.Id);
            order.ShippingStatus = ShippingStatus.Shipped;
            order.TrackingNumber = input.TrackingNumber;
            order.OrderStatus    = OrderStatus.Completed;
            await this.context.SaveChangesAsync();

            await this.inventoryService.RecalculateInventoryAfterShippingAsync(order.Id, order.WarehouseId);
        }