/// <summary> /// Method to return user/users infromation. - RS /// </summary> /// <param name="userId">passed user id</param> /// <returns>user/users information</returns> public async Task <List <UserRoleAc> > GetUserRoleAsync(string userId) { ApplicationUser applicationUser = await _userManager.FindByIdAsync(userId); var employeeRole = (await _userManager.GetRolesAsync(applicationUser)).First(); List <UserRoleAc> userRoleAcList = new List <UserRoleAc>(); if (employeeRole == _stringConstant.Admin) //If login user is admin then return all active users with role. { //getting the all user infromation. var userRole = new UserRoleAc(applicationUser.Id, applicationUser.UserName, applicationUser.FirstName + " " + applicationUser.LastName, employeeRole); userRoleAcList.Add(userRole); //getting employee role id. var roleId = (await _roleManager.Roles.SingleAsync(x => x.Name == _stringConstant.Employee)).Id; //getting active employee list. var userList = await _applicationUserDataRepository.Fetch(y => y.IsActive && y.Roles.Any(x => x.RoleId == roleId)).ToListAsync(); foreach (var user in userList) { var userRoleAc = new UserRoleAc(user.Id, user.UserName, user.FirstName + " " + user.LastName, employeeRole); userRoleAcList.Add(userRoleAc); } } else //If login user is team leader/employee then return own infromation with his role. { //check login user is teamLeader or not. var isProjectExists = await _projectDataRepository.FirstOrDefaultAsync(x => x.TeamLeaderId == applicationUser.Id); //If isProjectExists is null then user role is employee other wise user role is teamleader. var userRoleAc = new UserRoleAc(applicationUser.Id, applicationUser.UserName, applicationUser.FirstName + " " + applicationUser.LastName, (isProjectExists != null ? _stringConstant.TeamLeader : _stringConstant.Employee)); userRoleAcList.Add(userRoleAc); } return(userRoleAcList); }
public async Task <IActionResult> Index() { if (User.Identity.IsAuthenticated) { var user = await _userManager.FindByNameAsync(User.Identity.Name); UserRoleAc userRole; if (User.IsInRole(_stringConstant.Admin)) { userRole = new UserRoleAc(user.Id, user.Email, user.FirstName, _stringConstant.Admin); } else { userRole = new UserRoleAc(user.Id, user.Email, user.FirstName, _stringConstant.Employee); } ViewData["UserRole"] = userRole; return(View("Index")); } return(RedirectToAction("Login", "Account")); }
/// <summary> /// Method to return list of teamMembers. - RS /// </summary> /// <param name="userId">Passed user id</param> /// <returns>teamMembers information</returns> public async Task <List <UserRoleAc> > GetTeamMembersAsync(string userId) { ApplicationUser applicationUser = await _userManager.FindByIdAsync(userId); var userRoleAcList = new List <UserRoleAc>(); var userRoleAc = new UserRoleAc(applicationUser.Id, applicationUser.UserName, applicationUser.FirstName + " " + applicationUser.LastName, _stringConstant.TeamLeader); userRoleAcList.Add(userRoleAc); //Get projectid's for that specific teamleader IEnumerable <int> projectIds = await _projectDataRepository.Fetch(x => x.TeamLeaderId.Equals(applicationUser.Id)).Select(y => y.Id).ToListAsync(); //Get distinct userid's for projects with that particular teamleader var userIdList = await _projectUserRepository.Fetch(x => projectIds.Contains(x.ProjectId)).Select(y => y.UserId).Distinct().ToListAsync(); //getting list of user infromation. var userList = await _applicationUserDataRepository.Fetch(x => userIdList.Contains(x.Id)).ToListAsync(); foreach (var user in userList) { var usersRoleAc = new UserRoleAc(user.Id, user.UserName, user.FirstName + " " + user.LastName, _stringConstant.Employee); userRoleAcList.Add(usersRoleAc); } return(userRoleAcList); }