public async Task CreateAdmin(string email)
        {
            if (await _identityRepository.IsEmailInUse(email, Roles.SystemAdmin) ||
                await _pendingIdentityRepository.IsEmailInUse(email, Roles.SystemAdmin))
            {
                throw new VmsException(Codes.EmailInUse, "The email supplied is already in use.");
            }

            var pending = new PendingIdentity(Guid.NewGuid(), email, Roles.SystemAdmin);

            await _pendingIdentityRepository.AddAsync(pending);

            _logger.LogInformation($"create code issued: {pending.Id}.");

            _serviceBus.PublishEvent(new PendingAdminCreated(pending.Id, pending.Email), RequestInfo.Empty);
        }
        public async Task CreateBusinessAdmin(string email, Guid businessId)
        {
            if (await _identityRepository.IsEmailInUse(email, Roles.BusinessAdmin) ||
                await _pendingIdentityRepository.IsEmailInUse(email, Roles.BusinessAdmin))
            {
                throw new VmsException(Codes.EmailInUse, "The email supplied is in use.");
            }

            if (!await _businessRepository.ContainsBusinessAsync(businessId))
            {
                //TODO: consider calling business service as back-up to avoid data inconsistency.
                throw new VmsException(Codes.BusinessNotFound,
                                       "The business cannot be found to create the account for.");
            }

            var pending = new PendingIdentity(Guid.NewGuid(), email, Roles.BusinessAdmin, businessId);

            await _pendingIdentityRepository.AddAsync(pending);

            _logger.LogInformation($"Pending identity for business admin created with email: {email} and code: {pending.Id}.");

            _serviceBus.PublishEvent(new PendingBusinessAdminCreated(pending.Id, pending.Email), RequestInfo.Empty);
        }
Exemple #3
0
        public async Task CreateUser(string email, Guid businessId)
        {
            if (await _identityRepository.IsEmailInUse(email, Roles.BusinessAdmin) ||
                await _identityRepository.IsEmailInUse(email, Roles.StandardPortalUser) ||
                await _pendingIdentityRepository.IsEmailInUse(email, Roles.BusinessAdmin) ||
                await _pendingIdentityRepository.IsEmailInUse(email, Roles.StandardPortalUser))
            {
                _logger.LogWarning($"Create user failed as a user with {email} already exists.");
                throw new VmsException(Codes.EmailInUse, $"The email: {email} already has an account registered with it.");
            }

            if (!await _businessRepository.ContainsBusinessAsync(businessId))
            {
                _logger.LogWarning("The business id used cannot be found.");
                throw new VmsException(Codes.BusinessNotFound, "The business with the id cannot be found");
            }

            var pending = new PendingIdentity(Guid.NewGuid(), email, Roles.StandardPortalUser, businessId);
            await _pendingIdentityRepository.AddAsync(pending);

            _logger.LogInformation($"User account registration created with code: {pending.Id}. for user with email: {pending.Email}");
            //TODO: Send email to user through email Service.
        }
Exemple #4
0
 public Task RemoveAsync(PendingIdentity pending) => _repository.RemoveAsync(pending.Id);
Exemple #5
0
 public Task AddAsync(PendingIdentity pending) =>
 _repository.AddAsync(pending);