Ejemplo n.º 1
0
        public bool IsLoggedAs(UserRoleCode role)
        {
            if (CurrentRole != null)
            {
                return(CurrentRole.Id == (int)role);
            }

            return(false);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 5
0
 public bool IsInRole(UserRoleCode role)
 {
     return(Roles.Any(r => r.Id == (int)role));
 }