Esempio n. 1
0
 private static Invite Convert(Documents.InviteDocument inviteDoc)
 {
     return(new Invite
     {
         id = inviteDoc.Id,
         actorId = inviteDoc.ActorId,
         email = inviteDoc.Email,
         lastSent = inviteDoc.LastSent,
     });
 }
Esempio n. 2
0
        internal async Task <TResult> CreateCredentialMappingAsync <TResult>(Guid credentialMappingId,
                                                                             Guid loginId, Guid actorId, string email, Guid token, DateTime lastSent, bool isToken, bool overrideLoginId,
                                                                             Func <TResult> onSuccess,
                                                                             Func <TResult> onAlreadyExists,
                                                                             Func <TResult> onTokenAlreadyInUse,
                                                                             Func <TResult> onLoginAlreadyInUse)
        {
            var rollback = new RollbackAsync <TResult>();

            var inviteDocument = new Documents.InviteDocument()
            {
                ActorId  = actorId,
                Email    = email,
                IsToken  = isToken,
                LastSent = lastSent,
                Token    = token,
                LoginId  = loginId,
            };

            rollback.AddTaskCreate(credentialMappingId, inviteDocument, onAlreadyExists, this.repository);

            var inviteTokenDocument = new Documents.InviteTokenDocument()
            {
                ActorId  = actorId,
                InviteId = credentialMappingId,
            };

            rollback.AddTaskCreate(token, inviteTokenDocument, onTokenAlreadyInUse, this.repository);

            if (overrideLoginId)
            {
                var oldActorId = default(Guid);
                rollback.AddTaskCreateOrUpdate(loginId,
                                               (Documents.LoginActorLookupDocument loginActorDocument) =>
                {
                    oldActorId = loginActorDocument.ActorId;
                    loginActorDocument.ActorId = actorId;
                    return(true);
                },
                                               (loginActorDocument) =>
                {
                    loginActorDocument.ActorId = oldActorId;
                    return(true);
                },
                                               () => { throw new Exception("Login override failed"); }, // Should never happend because always return true on mutate
                                               this.repository);
            }
            else
            {
                var loginActorDocument = new Documents.LoginActorLookupDocument()
                {
                    ActorId = actorId,
                };
                rollback.AddTaskCreate(loginId, loginActorDocument, onLoginAlreadyInUse, this.repository);
            }

            rollback.AddTaskCreateOrUpdate(actorId,
                                           (Documents.ActorMappingsDocument authDoc) => authDoc.AddInviteId(credentialMappingId),
                                           (authDoc) => authDoc.RemoveInviteId(credentialMappingId),
                                           onAlreadyExists, // This should fail on the action above as well
                                           this.repository);

            return(await rollback.ExecuteAsync(onSuccess));
        }