예제 #1
0
        public async Task <IActionResult> DeleteShipment(string id)
        {
            var shipment = await _shipmentService.GetShipmentById(id);

            if (shipment == null)
            {
                //No shipment found with the specified id
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentCustomer.IsStaff() && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)
            {
                return(RedirectToAction("List"));
            }

            var orderId = shipment.OrderId;
            var order   = await _orderService.GetOrderById(orderId);

            if (order == null)
            {
                //No order found with the specified id
                return(RedirectToAction("List"));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !_workContext.CurrentCustomer.IsStaff())
            {
                return(RedirectToAction("List"));
            }

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

                shipmentItem.ShipmentId = shipment.Id;
                if (product != null)
                {
                    await _productService.ReverseBookedInventory(product, shipmentItem);
                }
            }

            await _shipmentService.DeleteShipment(shipment);

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

            await _shipmentViewModelService.LogShipment(shipment.Id, $"A shipment #{shipment.ShipmentNumber} has been deleted");

            SuccessNotification(_localizationService.GetResource("Admin.Orders.Shipments.Deleted"));

            return(RedirectToAction("Edit", "Order", new { Id = order.Id }));
        }
예제 #2
0
        public async Task <IActionResult> DeleteShipment(string id)
        {
            var shipment = await _shipmentService.GetShipmentById(id);

            if (shipment == null)
            {
                //No shipment found with the specified id
                return(RedirectToAction("List"));
            }

            if (await _groupService.IsStaff(_workContext.CurrentCustomer) && shipment.StoreId != _workContext.CurrentCustomer.StaffStoreId)
            {
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentVendor != null && _workContext.CurrentVendor.Id != shipment.VendorId)
            {
                Error(_translationService.GetResource("Admin.Orders.Shipments.VendorAccess"));
                return(RedirectToAction("ShipmentDetails", new { id = shipment.Id }));
            }

            var orderId = shipment.OrderId;
            var order   = await _orderService.GetOrderById(orderId);

            if (order == null)
            {
                //No order found with the specified id
                return(RedirectToAction("List"));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && !_workContext.HasAccessToShipment(order, shipment) && !await _groupService.IsStaff(_workContext.CurrentCustomer))
            {
                return(RedirectToAction("List"));
            }

            //delete shipment
            await _shipmentService.DeleteShipment(shipment);

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

            await _shipmentViewModelService.LogShipment(shipment.Id, $"A shipment #{shipment.ShipmentNumber} has been deleted");

            Success(_translationService.GetResource("Admin.Orders.Shipments.Deleted"));

            return(RedirectToAction("Edit", "Order", new { Id = order.Id }));
        }
예제 #3
0
        public async Task Test_DeleteShipment_Is_Ok()
        {
            try
            {
                ShipmentModel currentShipmentModel =
                    await _shipmentService.Get(58);

                await _shipmentService.DeleteShipment(currentShipmentModel);
            }
            catch (Exception ex)
            {
                Assert.IsFalse(true);
            }
            Assert.IsTrue(true);
        }
예제 #4
0
        public async Task <bool> Delete(int id, int customerId, string language)
        {
            var currentUser = await _authenticationService.GetUser(User.Identity.Name);

            if (currentUser.CustomerId != customerId)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError, "Provided customer is not assigned to your account");
            }
            language.ConvertLocaleStringToServerLanguage();

            try
            {
                var shipment = await this.Get(id, customerId, "EN");

                await _shipmentService.DeleteShipment(shipment);
            }
            catch (Exception)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden, "Don't have permission to delete this addres");
            }

            return(true);
        }
        public async Task <ActionResult> DeleteShipment(int id)
        {
            RequestResponse <int> requestResponse = new RequestResponse <int>();

            try
            {
                requestResponse.Status = await _shipmentService.DeleteShipment(id);

                requestResponse.Message = requestResponse.Status == 1
                    ? Utility.ResponseHelper.ShipmentDeleted
                    : Utility.ResponseHelper.ShipmentDeleteError;

                if (_unitOfWork.HasChanges())
                {
                    await _unitOfWork.CompleteAsync();
                }
            }
            catch (Exception ex)
            {
                requestResponse.Status  = Utility.ResponseHelper.FailureCode;
                requestResponse.Message = ex.Message;
            }
            return(Ok(requestResponse));
        }
예제 #6
0
 /// <summary>
 /// Deletes a shipment
 /// </summary>
 /// <param name="shipment">Shipment</param>
 public void DeleteShipment([FromBody] Shipment shipment)
 {
     _shipmentService.DeleteShipment(shipment);
 }
        public async Task <Unit> Handle(DeleteShipmentCommand request, CancellationToken cancellationToken)
        {
            await _shipmentService.DeleteShipment(request.ShipmentID);

            return(await Task.FromResult(Unit.Value));
        }