[Api.HttpPatch] //(MatchAllBodyParameters = false)] public async static Task <IHttpResponse> UpdateAsync( [Property(Name = IntegrationIdPropertyName)] IRef <XIntegration> integrationRef, [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, ContentTypeResponse <XIntegration> onUpdated, NotFoundResponse onNotFound, ForbiddenResponse onForbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist, UnauthorizedResponse onUnauthorized) { return(await integrationRef.StorageUpdateAsync( async (integration, saveAsync) => { var accountId = integration.accountId; if (!await application.CanAdministerCredentialAsync(accountId, security)) { return onUnauthorized(); } return await await authorizationRef.StorageGetAsync( async authorization => { if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization)) { return onForbidden().AddReason("Authorization is not accessable to this account."); } integration.Method = authorization.Method; // method is used in the .mappingId integration.authorization = authorizationRef.Optional(); integration.methodName = await Auth.Method.ById(authorization.Method, application, method => method.name, () => string.Empty); await saveAsync(integration); return onUpdated(integration); }, () => onAuthorizationDoesNotExist().AsTask()); }, () => onNotFound(), onModificationFailures: StorageConstraintUniqueAttribute.ModificationFailure( (XIntegration x) => x.authorization, () => { // TODO: Check if mapping is to this integration and reply already created. return onForbidden().AddReason("Authorization is already in use."); }).AsArray())); }
public static Task <TResult> CreateWithAuthorization <TResult>( XIntegration integration, Authorization authorization, Func <TResult> onCreated, Func <TResult> onAlreadyExists, Func <string, TResult> onFailure) { integration.Method = authorization.Method; // method is used in the .mappingId return(integration .StorageCreateAsync( discard => onCreated(), () => onAlreadyExists(), onModificationFailures: StorageConstraintUniqueAttribute.ModificationFailure( (XIntegration x) => x.authorization, () => { // TODO: Check if mapping is to this integration and reply already created. return onFailure("Authorization is already mapped to another integration."); }).AsArray())); }