Exemplo n.º 1
0
        private async Task <Response> SendSignUpInvites(Guid userId)
        {
            var allInvites = (await _invitesService.GetInvites(authorId: userId)).Data.ToList();

            var emailsDistinct = allInvites.Select(x => x.Email).Distinct().ToList();

            if (emailsDistinct.Count == 0)
            {
                return(new Response());
            }

            foreach (var email in emailsDistinct)
            {
                var emailInvites = allInvites
                                   .Where(x => string.Equals(x.Email, email, StringComparison.CurrentCultureIgnoreCase))
                                   .OrderByDescending(x => x.EntityType)
                                   .ToList();
                var mainInvite = emailInvites.FirstOrDefault();
                if (mainInvite != null)
                {
                    await _invitesService.SendInvite(mainInvite.Email, mainInvite.EntityId, mainInvite.EntityType);
                }

                emailInvites.Remove(mainInvite);
                foreach (var secondaryInvite in emailInvites)
                {
                    await _invitesService.RemoveInvite(secondaryInvite.Email, secondaryInvite.EntityId, secondaryInvite.EntityType);
                }
            }

            return(new Response());
        }
Exemplo n.º 2
0
        private async Task <Response <IEnumerable <InviteSimpleDTO> > > GetInvitesByEntityId(Guid entityId, InviteEntityType entityType)
        {
            var invites = await _invitesService.GetInvites(null, entityId, entityType);

            return(new Response <IEnumerable <InviteSimpleDTO> >
            {
                Data = invites.Data
            });
        }
Exemplo n.º 3
0
        public async Task <Response> InviteUsers(Guid entityId, InviteEntityType entityType, Guid authorId, IEnumerable <string> emails, bool sendMails = true)
        {
            var distinctEmails = emails.Distinct().ToList();

            var existedUsersEmails = await GetExistedUsersInEntity(entityId, entityType, distinctEmails);

            var notExistedEmails = distinctEmails.Except(existedUsersEmails).ToList();
            var existedInvites   = await _invitesService.GetInvites(notExistedEmails, entityId, entityType);

            notExistedEmails = notExistedEmails.Except(existedInvites.Data.Select(x => x.Email)).ToList();

            foreach (var email in notExistedEmails)
            {
                await _invitesService.CreateInvite(email, entityId, entityType, authorId);

                if (sendMails)
                {
                    await _invitesService.SendInvite(email, entityId, entityType);
                }
            }

            return(new Response());
        }