public async Task <IActionResult> Approvers(string userId, string approverId) { if (string.IsNullOrEmpty(userId)) { _loggerService.LogError("User id is null"); return(NotFound()); } UserDTO user; try { user = await _userService.GetUserAsync(userId); } catch (Exception) { _loggerService.LogError($"User not found. UserId:{userId}"); return(NotFound()); } var confirmedUsers = _userService.GetConfirmedUsers(user); var canApprove = _userService.CanApprove(confirmedUsers, userId, await _userManager.GetUserAsync(User)); var time = await _userService.CheckOrAddPlastunRoleAsync(user.Id, user.RegistredOn); var clubApprover = _userService.GetClubAdminConfirmedUser(user); var cityApprover = _userService.GetCityAdminConfirmedUser(user); var model = new UserApproversViewModel { User = _mapper.Map <UserDTO, UserInfoViewModel>(user), canApprove = canApprove, TimeToJoinPlast = ((int)time.TotalDays), ConfirmedUsers = _mapper.Map <IEnumerable <ConfirmedUserDTO>, IEnumerable <ConfirmedUserViewModel> >(confirmedUsers), ClubApprover = _mapper.Map <ConfirmedUserDTO, ConfirmedUserViewModel>(clubApprover), CityApprover = _mapper.Map <ConfirmedUserDTO, ConfirmedUserViewModel>(cityApprover), IsUserHeadOfCity = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), "Голова Станиці"), IsUserHeadOfClub = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), "Голова Куреня"), IsUserHeadOfRegion = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), "Голова Округу"), IsUserPlastun = await _userManagerService.IsInRoleAsync(user, "Пластун") || !(await _userManagerService.IsInRoleAsync(user, "Прихильник") && await _userService.IsApprovedCityMember(userId)), CurrentUserId = approverId }; foreach (var item in model.ConfirmedUsers) { item.Approver.User.ImagePath = await _userService.GetImageBase64Async(item.Approver.User.ImagePath); } if (model.ClubApprover != null) { model.ClubApprover.Approver.User.ImagePath = await _userService.GetImageBase64Async(model?.ClubApprover?.Approver?.User.ImagePath); } if (model.CityApprover != null) { model.CityApprover.Approver.User.ImagePath = await _userService.GetImageBase64Async(model?.CityApprover?.Approver?.User.ImagePath); } return(Ok(model)); }
public async Task <IActionResult> Approvers(string userId) { try { if (string.IsNullOrEmpty(userId)) { _loggerService.LogError("User id is null"); return(RedirectToAction("HandleError", "Error", new { code = 500 })); } var user = await _userService.GetUserAsync(userId); var confirmedUsers = _userService.GetConfirmedUsers(user); var canApprove = await _userService.CanApproveAsync(confirmedUsers, userId, User); var time = await _userService.CheckOrAddPlastunRoleAsync(user.Id, user.RegistredOn); var clubApprover = _userService.GetClubAdminConfirmedUser(user); var cityApprover = _userService.GetCityAdminConfirmedUser(user); if (user != null) { var model = new UserApproversViewModel { User = _mapper.Map <UserDTO, UserViewModel>(user), canApprove = canApprove, TimeToJoinPlast = time, ConfirmedUsers = _mapper.Map <IEnumerable <ConfirmedUserDTO>, IEnumerable <ConfirmedUserViewModel> >(confirmedUsers), ClubApprover = _mapper.Map <ConfirmedUserDTO, ConfirmedUserViewModel>(clubApprover), CityApprover = _mapper.Map <ConfirmedUserDTO, ConfirmedUserViewModel>(cityApprover), IsUserHeadOfCity = await _userManagerService.IsInRoleAsync(user, "Голова Станиці"), IsUserHeadOfClub = await _userManagerService.IsInRoleAsync(user, "Голова Куреня"), IsUserHeadOfRegion = await _userManagerService.IsInRoleAsync(user, "Голова Округу"), IsUserPlastun = await _userManagerService.IsInRoleAsync(user, "Пластун"), CurrentUserId = await _userManagerService.GetUserIdAsync(User) }; return(View(model)); } _loggerService.LogError($"Can`t find this user:{userId}, or smth else"); return(RedirectToAction("HandleError", "Error", new { code = 500 })); } catch { _loggerService.LogError("Smth went wrong"); return(RedirectToAction("HandleError", "Error", new { code = 500 })); } }
public async Task <IActionResult> Approvers(string userId, string approverId) { if (string.IsNullOrEmpty(userId)) { _loggerService.LogError("User id is null"); return(NotFound()); } UserDTO user; try { user = await _userService.GetUserAsync(userId); } catch (Exception) { _loggerService.LogError($"User not found. UserId:{userId}"); return(NotFound()); } var currentUserId = _userManager.GetUserId(User); var currentUser = await _userService.GetUserAsync(currentUserId); var userRoles = (await _userManagerService.GetRolesAsync(user)).ToList(); var confirmedUsers = _userService.GetConfirmedUsers(user); var canApprove = !userRoles.Any(r => r == Roles.RegisteredUser || r == Roles.FormerPlastMember); var canApprovePlastMember = canApprove && _userService.CanApprove(confirmedUsers, userId, currentUserId, await _userManagerService.IsInRoleAsync(currentUser, Roles.Admin)); var time = _userService.CheckOrAddPlastunRole(user.Id, user.RegistredOn); var clubApprover = _userService.GetClubAdminConfirmedUser(user); var cityApprover = _userService.GetCityAdminConfirmedUser(user); var model = new UserApproversViewModel { User = _mapper.Map <UserDTO, UserInfoViewModel>(user), CanApprove = canApprove, CanApprovePlastMember = canApprovePlastMember, TimeToJoinPlast = ((int)time.TotalDays), ConfirmedUsers = _mapper.Map <IEnumerable <ConfirmedUserDTO>, IEnumerable <ConfirmedUserViewModel> >(confirmedUsers), ClubApprover = _mapper.Map <ConfirmedUserDTO, ConfirmedUserViewModel>(clubApprover), CityApprover = _mapper.Map <ConfirmedUserDTO, ConfirmedUserViewModel>(cityApprover), IsUserHeadOfCity = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), Roles.CityHead), IsUserHeadDeputyOfCity = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), Roles.CityHeadDeputy), IsUserHeadOfClub = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), Roles.KurinHead), IsUserHeadDeputyOfClub = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), Roles.KurinHeadDeputy), IsUserHeadOfRegion = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), Roles.OkrugaHead), IsUserHeadDeputyOfRegion = await _userManagerService.IsInRoleAsync(_mapper.Map <User, UserDTO>(await _userManager.GetUserAsync(User)), Roles.OkrugaHeadDeputy), IsUserPlastun = await _userManagerService.IsInRoleAsync(user, Roles.PlastMember) || user.UserProfile.UpuDegreeID != 1 || !(await _userManagerService.IsInRoleAsync(user, Roles.Supporter) && await _userService.IsApprovedCityMember(userId)), CurrentUserId = approverId }; foreach (var item in model.ConfirmedUsers) { item.Approver.User.ImagePath = await _userService.GetImageBase64Async(item.Approver.User.ImagePath); } if (model.ClubApprover != null) { model.ClubApprover.Approver.User.ImagePath = await _userService.GetImageBase64Async(model?.ClubApprover?.Approver?.User.ImagePath); } if (model.CityApprover != null) { model.CityApprover.Approver.User.ImagePath = await _userService.GetImageBase64Async(model?.CityApprover?.Approver?.User.ImagePath); } return(Ok(model)); }