public static Task <IHttpResponse> CreateAsync( [Property(Name = ProcessStep.IdPropertyName)] Guid processId, [PropertyOptional(Name = ProcessStep.PreviousPropertyName)] Guid?previousStepId, [Property(Name = ProcessStep.ResourcePropertyName)] Guid resourceId, [Property(Name = ProcessStep.StagePropertyName)] Guid processStageId, [Property(Name = ProcessStep.CreatedOnPropertyName)] DateTime createdOn, [PropertyOptional(Name = ProcessStep.ConfirmedByPropertyName)] Guid?confirmedById, [PropertyOptional(Name = ProcessStep.ConfirmedWhenPropertyName)] DateTime?confirmedWhen, [PropertyOptional(Name = ProcessStep.ResourceKeysPropertyName)] string[] resourceKeys, [PropertyOptional(Name = ProcessStep.ResourcesPropertyName)] Guid[] resources, EastFive.Api.Security security, IProvideUrl url, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStage> onStageNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(EastFive.Azure.Processes.CreateAsync(processId, processStageId, resourceId, createdOn, resourceKeys.NullToEmpty().Zip(resources.NullToEmpty(), (k, id) => k.PairWithValue(id)).ToArray(), previousStepId, confirmedWhen, confirmedById, security, () => onCreated(), () => onAlreadyExists(), () => onStageNotFound(), (why) => onFailure(why))); }
[Api.HttpPost] //(MatchAllBodyParameters = false)] public async static Task <HttpResponseMessage> CreateAsync( [Property(Name = AccountPropertyName)] Guid accountId, [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef, [Resource] AccountMapping accountMapping, Api.Azure.AzureApplication application, Api.SessionToken security, CreatedResponse onCreated, ForbiddenResponse onForbidden, UnauthorizedResponse onUnauthorized, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist, GeneralConflictResponse onFailure) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onUnauthorized()); } return(await await authorizationRef.StorageGetAsync( async authorization => { accountMapping.Method = authorization.Method; // method is used in the .mappingId var authorizationLookup = new AuthorizationLookup { accountMappingRef = accountMapping.mappingId, authorizationLookupRef = authorizationRef, }; return await await authorizationLookup.StorageCreateAsync( async(idDiscard) => { accountMapping.accountMappingLookup = await await authorization.ParseCredentailParameters( application, (accountKey, loginProvider) => { var lookup = new AccountMappingLookup() { accountkey = accountKey, accountMappingId = accountMapping.mappingId, Method = authorization.Method, }; return lookup.StorageCreateAsync( (discard) => new RefOptional <AccountMappingLookup>( lookup.accountMappingLookupId), () => new RefOptional <AccountMappingLookup>()); }, (why) => { var amLookupMaybe = new RefOptional <AccountMappingLookup>(); return amLookupMaybe.AsTask(); }); return await accountMapping.StorageCreateAsync( createdId => { return onCreated(); }, () => onForbidden().AddReason("Account is already mapped to that authentication.")); }, () => onFailure("Authorization is already mapped to another account.").AsTask()); }, () => onAuthenticationDoesNotExist().AsTask())); }
[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())); }
[Api.HttpPatch] //(MatchAllBodyParameters = false)] public async static Task <HttpResponseMessage> UpdateAsync( [Property(Name = IntegrationIdPropertyName)] IRef <Integration> integrationRef, [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, ContentTypeResponse <Integration> onUpdated, NotFoundResponse onNotFound, NotModifiedResponse onNotModified, ForbiddenResponse onForbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist, 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 => { // TODO? This // var accountIdDidMatch = await await authorization.ParseCredentailParameters( integration.Method = authorization.Method; // method is used in the .mappingId integration.authorization = authorizationRef.Optional(); return await await SaveAuthorizationLookupAsync(integration.integrationRef, authorization.authorizationRef, async() => { await saveAsync(integration); return await SaveAccountLookupAsync(accountId, integration, () => onUpdated(integration)); }, () => { // TODO: Check if mapping is to this integration and reply already created. return onForbidden().AddReason("Authorization is already in use.").AsTask(); }); }, () => { return onNotModified().AsTask(); }); }, () => onNotFound())); }
public static Task <HttpResponseMessage> CreateAsync( [Property(Name = Resources.ProcessStage.IdPropertyName)] Guid processStageId, [Property(Name = Resources.ProcessStage.OwnerPropertyName)] Guid ownerId, [Property(Name = Resources.ProcessStage.TypePropertyName)] Guid processStageTypeId, [PropertyOptional(Name = Resources.ProcessStage.TitlePropertyName)] string title, [PropertyOptional(Name = Resources.ProcessStage.ViewablePropertyName)] Guid [] viewableIds, [PropertyOptional(Name = Resources.ProcessStage.CompletablePropertyName)] Guid [] completableIds, [PropertyOptional(Name = Resources.ProcessStage.EditablePropertyName)] Guid [] editableIds, [PropertyOptional(Name = Resources.ProcessStage.ConfirmablePropertyName)] Resources.ProcessStage.ConfirmableResource [] confirmables, EastFive.Api.Security security, EastFive.Api.Azure.AzureApplication application, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStageType> onTypeDoesNotExist, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStage> onConfirmationStageDoesNotExist, ReferencedDocumentDoesNotExistsResponse <BlackBarLabs.Api.ResourceBase> onActorDoesNotExists, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(EastFive.Azure.ProcessStages.CreateAsync(processStageId, ownerId, processStageTypeId, title, viewableIds, editableIds, completableIds, confirmables .Select( confirmable => confirmable.ProcessStageNext.ToGuid().Value .PairWithKey( confirmable.Positions .Select(position => position.ToGuid().Value) .ToArray())) .ToArray(), security, () => onCreated(), () => onAlreadyExists(), () => onTypeDoesNotExist(), (missingStageId) => onConfirmationStageDoesNotExist(), () => onActorDoesNotExists(), (why) => onFailure(why))); }
public async static Task <IHttpResponse> CreateAsync( [Property(Name = AccountPropertyName)] Guid accountId, [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe, [Resource] XIntegration integration, IAuthApplication application, EastFive.Api.SessionToken security, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ForbiddenResponse onForbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist, GeneralConflictResponse onFailure) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onForbidden()); } return(await await authorizationRefMaybe.StorageGetAsync( async authorization => { if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization)) { return onFailure("Authorization is not accessable to this account."); } return await CreateWithAuthorization(integration, authorization, () => onCreated(), () => onAlreadyExists(), (why) => onFailure(why)); }, async() => { if (authorizationRefMaybe.HasValue) { return onAuthorizationDoesNotExist(); } return await integration.StorageCreateAsync( (discard) => onCreated(), () => onAlreadyExists()); })); }
[Api.HttpPost] //(MatchAllBodyParameters = false)] public async static Task <IHttpResponse> CreateAsync( [Property(Name = AccountPropertyName)] Guid accountId, [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe, [Resource] Integration integration, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ForbiddenResponse forbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist, GeneralConflictResponse onFailure) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(forbidden()); } return(await await authorizationRefMaybe.StorageGetAsync( authorization => { // TODO? This // var accountIdDidMatch = await await authorization.ParseCredentailParameters( return CreateWithAuthorization(integration, authorization, accountId, () => onCreated(), () => onAlreadyExists(), (why) => onFailure(why)); }, async() => { return await await integration.StorageCreateAsync( discard => { return SaveAccountLookupAsync(accountId, integration, () => onCreated()); }, () => onAlreadyExists().AsTask()); })); }
public async static Task <IHttpResponse> CreateAsync( [Api.Meta.Flows.WorkflowNewId] [Property(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef, [Api.Meta.Flows.WorkflowParameter(Value = "{{AuthenticationMethod}}")] [Property(Name = MethodPropertyName)] IRef <Method> method, [Api.Meta.Flows.WorkflowParameter(Value = "http://example.com")] [Property(Name = LocationAuthorizationReturnPropertyName)] Uri locationAuthenticationReturn, [Resource] Authorization authorization, IAuthApplication application, IProvideUrl urlHelper, CreatedBodyResponse <Authorization> onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Method> onAuthenticationDoesNotExist) { authorization.accountIdMaybe = default; authorization.authorized = false; return(await await Auth.Method.ById(method, application, async (method) => { //var authorizationIdSecure = authentication.authenticationId; authorization.LocationAuthentication = await method.GetLoginUrlAsync( application, urlHelper, authorizationRef.id); //throw new ArgumentNullException(); return await authorization.StorageCreateAsync( createdId => onCreated(authorization), () => onAlreadyExists()); }, () => onAuthenticationDoesNotExist().AsTask())); }
public async static Task <HttpResponseMessage> CreateAsync( [Property(Name = AuthorizationIdPropertyName)] Guid authorizationId, [Property(Name = MethodPropertyName)] IRef <Method> method, [Property(Name = LocationAuthorizationReturnPropertyName)] Uri LocationAuthenticationReturn, [Resource] Authorization authorization, Api.Azure.AzureApplication application, UrlHelper urlHelper, CreatedBodyResponse <Authorization> onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Method> onAuthenticationDoesNotExist) { return(await await Auth.Method.ById(method, application, async (authentication) => { //var authorizationIdSecure = authentication.authenticationId; authorization.LocationAuthentication = await authentication.GetLoginUrlAsync( application, urlHelper, authorizationId); throw new NotImplementedException(); return await authorization.StorageCreateAsync( createdId => onCreated(authorization), () => onAlreadyExists()); }, () => onAuthenticationDoesNotExist().AsTask())); }