Esempio n. 1
0
        private async void VerifyUserEmailAsync(ApplicationUser user)
        {
            //Verify email address is confirmed with identity
            var emailConfirmed = userManager.IsEmailConfirmedAsync(user).Result;

            if (!emailConfirmed)
            {
                string emailVerificationToken = userManager.GenerateEmailConfirmationTokenAsync(user).Result;
                var    result = userManager.ConfirmEmailAsync(user, emailVerificationToken).Result;

                if (result.Succeeded)
                {
                    var emailVerification = emailVerificationRepository.Find(null, p => p.PersonId == user.PersonId && p.IsVerified != true)?.Items?.FirstOrDefault();
                    if (emailVerification != null)
                    {
                        var verifiedEmailAddress = personEmailRepository.Find(null, p => p.Address.Equals(emailVerification.Address, StringComparison.OrdinalIgnoreCase))?.Items?.FirstOrDefault();
                        if (verifiedEmailAddress == null)
                        {
                            var personEmail = new PersonEmail()
                            {
                                EmailVerificationId = emailVerification.Id,
                                IsPrimaryEmail      = true,
                                PersonId            = emailVerification.PersonId,
                                Address             = emailVerification.Address
                            };
                            personEmailRepository.Add(personEmail);
                        }

                        //Verification completed
                        emailVerification.IsVerified = true;
                        emailVerificationRepository.Update(emailVerification);
                    }
                }
            }
        }
        public PaginatedList <TeamMemberViewModel> GetPeopleInOrganization(Guid organizationId, string sortColumn, OrderByDirectionType direction = OrderByDirectionType.Ascending, int skip = 0, int take = 100)
        {
            PaginatedList <TeamMemberViewModel> team = new PaginatedList <TeamMemberViewModel>
            {
                ParentId = organizationId
            };

            var org = _organizationRepo.GetOne(organizationId);

            if (org == null)
            {
                throw new KeyNotFoundException();
            }

            bool   orgHasEmailDomain = false;
            string emailDomainWithAt = string.Empty;

            var members = _organzationMemberRepo.Find(organizationId);

            team.TotalCount = members.Items.Count;

            var personIds = members.Items.Select(om => om.PersonId).Distinct().ToArray();

            var people = _personRepo.Find(null, p => personIds.Contains(p.Id));
            var emails = _emailVerificationRepository.Find(null, e => personIds.Contains(e.PersonId));

            foreach (OrganizationMember member in members.Items.Skip(skip).Take(take))
            {
                TeamMemberViewModel teamMember = new TeamMemberViewModel
                {
                    OrganizationMemberId = member.Id.Value,
                    PersonId             = member.PersonId.Value,
                    JoinedOn             = member.CreatedOn.Value,
                    InvitedBy            = member.InvitedBy,
                    IsAdmin = member.IsAdministrator.GetValueOrDefault(false)
                };

                var person = people.Items.Where(p => p.Id.Equals(member.PersonId)).FirstOrDefault();
                if (person != null)
                {
                    teamMember.UserName = person.Name;
                    teamMember.Name     = person.Name;
                    teamMember.Status   = "InActive";
                    if (orgHasEmailDomain)
                    {
                        var matchingEmailList     = emails.Items.Where(e => e.PersonId.Equals(member.PersonId) && e.Address.EndsWith(emailDomainWithAt)).ToList();
                        var orderedList           = matchingEmailList.OrderBy(x => x.CreatedOn);
                        var correctEmailForMember = orderedList.FirstOrDefault();

                        if (correctEmailForMember != null)
                        {
                            teamMember.EmailAddress = correctEmailForMember.Address;
                            teamMember.Status       = correctEmailForMember.IsVerified.GetValueOrDefault(false) ? "Active" : "InActive";
                        }
                    }
                    if (string.IsNullOrEmpty(teamMember.EmailAddress))
                    {
                        var matchingEmailList     = emails.Items.Where(e => e.PersonId.Equals(member.PersonId)).ToList();
                        var orderedList           = matchingEmailList.OrderBy(x => x.CreatedOn);
                        var correctEmailForMember = orderedList.FirstOrDefault();

                        if (correctEmailForMember != null)
                        {
                            teamMember.EmailAddress = correctEmailForMember.Address;
                            teamMember.Status       = correctEmailForMember.IsVerified.GetValueOrDefault(false) ? "Active" : "InActive";
                        }
                    }
                }

                team.Add(teamMember);
            }

            if (!string.IsNullOrWhiteSpace(sortColumn))
            {
                if (direction == OrderByDirectionType.Ascending)
                {
                    team.Items = team.Items.OrderBy(t => t.GetType().GetProperty(sortColumn).GetValue(t)).ToList();
                }
                else if (direction == OrderByDirectionType.Descending)
                {
                    team.Items = team.Items.OrderByDescending(t => t.GetType().GetProperty(sortColumn).GetValue(t)).ToList();
                }
            }

            return(team);
        }