public async Task <UserInvite> Create(string email, string roleId, Guid createdById)
        {
            var existingInvite = await _usersAndRolesDbContext
                                 .UserInvites
                                 .AsQueryable()
                                 .SingleOrDefaultAsync(i => i.Email.ToLower().Equals(email.ToLower()));

            if (existingInvite != null)
            {
                return(existingInvite);
            }

            var newInvite = new UserInvite
            {
                Email       = email.ToLower(),
                RoleId      = roleId,
                Created     = DateTime.UtcNow,
                CreatedById = createdById.ToString(),
            };

            _usersAndRolesDbContext.Add(newInvite);
            await _usersAndRolesDbContext.SaveChangesAsync();

            return(newInvite);
        }
Пример #2
0
        private async Task CreateNewUserReleaseInvite(Guid releaseId, string email)
        {
            var hasExistingInvite = await _context
                                    .UserReleaseInvites
                                    .Where(
                i =>
                i.ReleaseId == releaseId &&
                i.Email.ToLower() == email.ToLower() &&
                i.Role == ReleaseRole.PrereleaseViewer
                )
                                    .AnyAsync();

            if (hasExistingInvite)
            {
                return;
            }

            _context.Add(
                new UserReleaseInvite
            {
                Email       = email.ToLower(),
                ReleaseId   = releaseId,
                Role        = ReleaseRole.PrereleaseViewer,
                Created     = UtcNow,
                CreatedById = _userService.GetUserId()
            }
                );
            await _context.SaveChangesAsync();

            var hasExistingSystemInvite = await _usersAndRolesDbContext
                                          .UserInvites
                                          .Where(i => i.Email.ToLower() == email.ToLower())
                                          .AnyAsync();

            // TODO EES-1181 - allow multiple invites per email address to allow people to
            // be assigned multiple roles upon first login
            if (!hasExistingSystemInvite)
            {
                var role = await GetPreReleaseUserRole();

                _usersAndRolesDbContext.Add(
                    new UserInvite
                {
                    Email   = email.ToLower(),
                    Role    = role,
                    Created = UtcNow,
                    // TODO
                    CreatedBy = ""
                }
                    );

                await _usersAndRolesDbContext.SaveChangesAsync();
            }
        }