Example #1
0
        public async Task <ExternalAccount> AddExternalAccountAsync(Guid userAccountId, string email, string provider, string subject)
        {
            var now             = DateTime.UtcNow; // TODO: user time service
            var externalAccount = new ExternalAccount
            {
                UserAccountId  = userAccountId,
                Email          = email,
                Provider       = provider,
                Subject        = subject,
                CreatedAt      = now,
                UpdatedAt      = now,
                LastLoginAt    = null,
                IsLoginAllowed = true
            };

            await _userAccountStore.WriteExternalAccountAsync(externalAccount);

            // Emit event
            await _eventService.RaiseSuccessfulUserAccountUpdatedEventAsync(userAccountId);

            return(externalAccount);
        }
        public async Task UpdateLastUsedExternalAccountAsync(
            UserAccount userAccount,
            string provider,
            string subject)
        {
            var externalAccount = userAccount.Accounts
                                  .FirstOrDefault(c =>
                                                  c.Provider.Equals(provider) &&
                                                  c.Subject.Equals(subject)
                                                  );

            // TODO: user time service
            var now = DateTime.UtcNow;

            externalAccount.LastLoginAt = now;
            externalAccount.UpdatedAt   = now;

            await userAccountStore.WriteExternalAccountAsync(externalAccount);

            // Emit event
            eventService.RaiseSuccessfulUserAccountUpdatedEventAsync(
                externalAccount.UserAccountId);
        }