예제 #1
0
        public bool IsLoggedAs(UserRoleCode role)
        {
            if (CurrentRole != null)
            {
                return(CurrentRole.Id == (int)role);
            }

            return(false);
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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"));
        }
예제 #5
0
 public bool IsInRole(UserRoleCode role)
 {
     return(Roles.Any(r => r.Id == (int)role));
 }