public bool IsLoggedAs(UserRoleCode role) { if (CurrentRole != null) { return(CurrentRole.Id == (int)role); } return(false); }
public UserRole GetUserRoleByCode(UserRoleCode roleId) { try { return(_unitOfWork.UserRoleRepository.Get((int)roleId)); } catch (Exception ex) { _logManager.DefaultLogger.Error.Write("Mentoring.Application.UserRoleService.GetUserRoleByCode", ex); return(null); } }
public void RemoveRole(int id, UserRoleCode roleId) { try { var user = _unitOfWork.UserRepository.Search(u => u.Id == id, null, "Roles").FirstOrDefault(); var role = _unitOfWork.UserRoleRepository.Search(r => r.Id == (int)roleId).FirstOrDefault(); if (role != null) { user.Roles.Remove(role); _unitOfWork.UserRepository.Update(user); _unitOfWork.Save(); _userLogService.Add(user.Id, UserLogAction.RoleChange, string.Format(Resources.Messages.RemovedCareer, user.Name)); } } catch (Exception ex) { _logManager.DefaultLogger.Error.Write("Mentoring.Application.UserService.RemoveRole", ex); } }
public ActionResult SetAsInactive(int userId, UserRoleCode userRole) { var currentUser = UserHelper.GetCurrentUserInfo(); if (currentUser.IsInRole(UserRoleCode.Career)) { if (userRole == UserRoleCode.Mentor) { var mentor = _mentorService.GetByUserId(userId); mentor.Status = MentorStatus.Inactive; _mentorService.UpdateMentor(mentor); } if (userRole == UserRoleCode.Mentee) { var mentee = _menteeService.GetByUserId(userId); mentee.Status = MenteeStatus.Inactive; _menteeService.UpdateMentee(mentee); } } return(RedirectToAction("Index")); }
public bool IsInRole(UserRoleCode role) { return(Roles.Any(r => r.Id == (int)role)); }