예제 #1
0
        public virtual async Task <ActionResult> TriggerAction(string id, string action, IFormCollection collection)
        {
            if (string.IsNullOrWhiteSpace(action) || !actionEvents.IsValidAction <TUpdateDto>(action))
            {
                return(HandleReadException());
            }

            dynamic args = null;

            if (collection != null)
            {
                args = collection.ToExpandoObject();
            }

            var cts = TaskHelper.CreateNewCancellationTokenSource();

            try
            {
                var eventDto = new ActionDto()
                {
                    Action = action,
                    Args   = args
                };

                var result = await Service.TriggerActionAsync(id, eventDto, Username, cts.Token);

                if (result.IsFailure)
                {
                    return(HandleReadException());
                }
                else
                {
                    return(RedirectToControllerDefault().WithSuccess(this, Messages.ActionSuccessful));
                }
            }
            catch
            {
                return(HandleReadException());
            }
        }