public override Task <HttpResponseMessage> InvokeActionAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            DomainController controller = (DomainController)actionContext.ControllerContext.Controller;

            controller.ActionContext = actionContext;
            return(base.InvokeActionAsync(actionContext, cancellationToken));
        }
        public override Task <object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary <string, object> arguments, CancellationToken cancellationToken)
        {
            return(TaskHelpers.RunSynchronously(() =>
            {
                DomainController controller = (DomainController)controllerContext.Controller;
                object[] paramValues = arguments.Select(p => p.Value).ToArray();

                return _method.Invoke(controller, paramValues);
            }, cancellationToken));
        }
        public override Task <object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary <string, object> arguments, CancellationToken cancellationToken)
        {
            return(TaskHelpers.RunSynchronously <object>(() =>
            {
                // create a changeset from the entries
                ChangeSet changeSet = new ChangeSet((IEnumerable <ChangeSetEntry>)arguments[ChangeSetParameterName]);
                changeSet.SetEntityAssociations();

                DomainController controller = (DomainController)controllerContext.Controller;
                if (!controller.Submit(changeSet) &&
                    controller.ActionContext.Response != null)
                {
                    // If the submit failed due to an authorization failure,
                    // return the authorization response directly
                    return controller.ActionContext.Response;
                }

                // return the entries
                return controllerContext.Request.CreateResponse <ChangeSetEntry[]>(HttpStatusCode.OK, changeSet.ChangeSetEntries.ToArray());
            }, cancellationToken));
        }
        public override Task <object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary <string, object> arguments, CancellationToken cancellationToken)
        {
            return(TaskHelpers.RunSynchronously <object>(() =>
            {
                // create the changeset
                object entity = arguments.Single().Value; // there is only a single parameter - the entity being submitted
                ChangeSetEntry[] changeSetEntries = new ChangeSetEntry[]
                {
                    new ChangeSetEntry
                    {
                        Id = 1,
                        ActionDescriptor = _updateAction,
                        Entity = entity,
                        Operation = _updateAction.ChangeOperation
                    }
                };
                ChangeSet changeSet = new ChangeSet(changeSetEntries);
                changeSet.SetEntityAssociations();

                DomainController controller = (DomainController)controllerContext.Controller;
                if (!controller.Submit(changeSet) &&
                    controller.ActionContext.Response != null)
                {
                    // If the submit failed due to an authorization failure,
                    // return the authorization response directly
                    return controller.ActionContext.Response;
                }

                // return the entity
                entity = changeSet.ChangeSetEntries[0].Entity;
                // REVIEW does JSON make sense here?
                return new HttpResponseMessage()
                {
                    Content = new ObjectContent(_updateAction.EntityType, entity, new JsonMediaTypeFormatter())
                };
            }, cancellationToken));
        }