Beispiel #1
0
        public IActionResult CancelOrder(string orderGuid, int cancelReasonId)
        {
            var order = _orderService.GetByGuid(orderGuid);

            if (order == null || order.UserId != CurrentUser.Id)
            {
                return(NotFound());
            }
            if (!CanCancelOrder(order))
            {
                return(R.Fail.With("error", T("Unable to cancel the order")).Result);
            }

            var reason = _customLabelService
                         .FirstOrDefault(x => x.Type == CancellationReasonLabel && x.Id == cancelReasonId)?.Text;

            _orderAccountant.CancelOrder(order, reason);
            if (order.OrderStatus == OrderStatus.Cancelled)
            {
                RaiseEvent(NamedEvent.OrderCancelled);
            }
            return(R.Success.Result);
        }