private UserInfoViewModel GetUser(ApplicationUser user) { var roles = UserManager.GetRoles(user.Id); var claims = new List <UserClaimViewModel>(); foreach (var claim in user.Claims) { claims.Add(new UserClaimViewModel() { Type = claim.ClaimType, Value = claim.ClaimValue }); } string firstName = ""; string lastName = ""; Organization affiliation = null; var personNameIdClaim = claims.FirstOrDefault(n => n.Type == "personNameId"); if (personNameIdClaim != null) { var personNameId = Convert.ToInt32(personNameIdClaim.Value); var personName = new PersonNameRepo().Get(personNameId); firstName = personName.FirstName; lastName = personName.LastName; } var organizationIdClaim = claims.FirstOrDefault(n => n.Type == "organizationId"); if (personNameIdClaim != null) { var organizationId = Convert.ToInt32(organizationIdClaim.Value); affiliation = new OrganizationRepo().Get(organizationId); } if (roles.Contains("Judge")) { var judges = new JudgeService(new JudgeRepo(), new ContestJudgeRepo()).GetAll().Where(j => j.UserId == user.Id); foreach (var judge in judges) { claims.Add(new UserClaimViewModel() { Type = "judgeId", Value = judge.Id.ToString() }); } } var contests = new ContestService(new ContestRepo(), new ShowContestRepo()).GetAll().Where(c => c.TimeKeeperId == user.Id); if (contests.Any()) { roles.Add("TimeKeeper"); } return(new UserInfoViewModel { Id = user.Id, Email = user.UserName, FirstName = firstName, LastName = lastName, Affiliation = affiliation, Roles = roles, Claims = claims }); }