[HttpPost, ActionName("Edit")]
[FormValueRequired("btnSaveOrderStatus")]
public virtual IActionResult ChangeOrderStatus(int id, OrderModel model)
{
if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
return AccessDeniedView();
//try to get an order with the specified id
var order = _orderService.GetOrderById(id);
if (order == null)
return RedirectToAction("List");
//a vendor does not have access to this functionality
if (_workContext.CurrentVendor != null)
return RedirectToAction("Edit", "Order", new { id });
try
{
order.OrderStatusId = model.OrderStatusId;
_orderService.UpdateOrder(order);
//add a note
order.OrderNotes.Add(new OrderNote
{
Note = $"Order status has been edited. New status: {_localizationService.GetLocalizedEnum(order.OrderStatus)}",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow
});
_orderService.UpdateOrder(order);
LogEditOrder(order.Id);
//prepare model
model = _orderModelFactory.PrepareOrderModel(model, order);
return View(model);
}
catch (Exception exc)
{
//prepare model
model = _orderModelFactory.PrepareOrderModel(model, order);
_notificationService.ErrorNotification(exc);
return View(model);
}
}