private static string GetAuthorizeMethodName(ChangeSetEntry entry) { switch (entry.Type) { case ChangeSetEntryType.DataModification: DataModificationEntry dataModification = (DataModificationEntry)entry; string operationName = null; if (dataModification.IsNew) { operationName = ConventionBasedChangeSetConstants.AuthorizeMethodDataModificationInsert; } else if (dataModification.IsUpdate) { operationName = ConventionBasedChangeSetConstants.AuthorizeMethodDataModificationUpdate; } else if (dataModification.IsDelete) { operationName = ConventionBasedChangeSetConstants.AuthorizeMethodDataModificationDelete; } return(operationName + dataModification.EntitySetName); case ChangeSetEntryType.ActionInvocation: ActionInvocationEntry actionEntry = (ActionInvocationEntry)entry; return(ConventionBasedChangeSetConstants.AuthorizeMethodActionInvocationExecute + actionEntry.ActionName); default: throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, Resources.InvalidChangeSetEntryType, entry.Type)); } }
private static string GetMethodName(ChangeSetEntry entry, string suffix) { switch (entry.Type) { case ChangeSetEntryType.DataModification: DataModificationEntry dataModification = (DataModificationEntry)entry; string operationName = null; if (dataModification.IsNew) { operationName = "Insert"; } else if (dataModification.IsUpdate) { operationName = "Updat"; } else if (dataModification.IsDelete) { operationName = "Delet"; } return("On" + operationName + suffix + dataModification.EntitySetName); case ChangeSetEntryType.ActionInvocation: ActionInvocationEntry actionEntry = (ActionInvocationEntry)entry; return("OnExecut" + suffix + actionEntry.ActionName); default: throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, Resources.InvalidChangeSetEntryType, entry.Type)); } }
private static object[] GetParameters(ChangeSetEntry entry) { switch (entry.Type) { case ChangeSetEntryType.DataModification: DataModificationEntry dataModification = (DataModificationEntry)entry; return(new object[] { dataModification.Entity }); case ChangeSetEntryType.ActionInvocation: ActionInvocationEntry actionEntry = (ActionInvocationEntry)entry; return(actionEntry.GetArgumentArray()); default: throw new InvalidOperationException(string.Format( CultureInfo.InvariantCulture, Resources.InvalidChangeSetEntryType, entry.Type)); } }
/// <summary> /// Handles a POST request to an action. /// </summary> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The task object that contains the action result.</returns> public async Task <IHttpActionResult> PostAction(CancellationToken cancellationToken) { ODataPath path = this.GetPath(); UnboundActionPathSegment actionPathSegment = path.Segments.Last() as UnboundActionPathSegment; if (actionPathSegment == null) { throw new NotSupportedException(Resources.PostToUnboundActionNotSupported); } ActionInvocationEntry entry = new ActionInvocationEntry(actionPathSegment.ActionName, null); RestierChangeSetProperty changeSetProperty = this.Request.GetChangeSet(); if (changeSetProperty == null) { ChangeSet changeSet = new ChangeSet(); changeSet.Entries.Add(entry); SubmitResult result = await Api.SubmitAsync(changeSet, cancellationToken); } else { changeSetProperty.ChangeSet.Entries.Add(entry); await changeSetProperty.OnChangeSetCompleted(); } if (entry.Result != null) { return(this.CreateOKResult(entry.Result)); } else { // TODO: Should also be able to handle 204. return(this.StatusCode(HttpStatusCode.NotImplemented)); } }