Example #1
0
        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);
        }
Example #2
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.
        }