Exemplo n.º 1
0
        public static MvcHtmlString RenderLayout(this HtmlHelper helper, bool isAuthorize, string role)
        {
            StringBuilder builder = new StringBuilder();

            if (isAuthorize)
            {
                if (role == RoleDistributer.GetAdminRole())
                {
                    builder.Append(helper.Partial("_AdminLayout"));
                }
                else if (role == RoleDistributer.GetStudentRole())
                {
                    builder.Append(helper.Partial("_StudentLayout"));
                }
                else if (role == RoleDistributer.GetTeacherRole())
                {
                    builder.Append(helper.Partial("_TeacherLayout"));
                }
                else if (role == RoleDistributer.GetBlockRole())
                {
                    builder.Append(helper.Partial("_BlockedLayout"));
                }
            }
            else
            {
                builder.Append(helper.Partial("_NotAuthorizeLayout"));
            }
            return(MvcHtmlString.Create(builder.ToString()));
        }
Exemplo n.º 2
0
        public IEnumerable <UserDTO> GetBlockStudents()
        {
            var role  = _database.RoleManager.FindByName(RoleDistributer.GetBlockRole());
            var users = _database.UserManager.Users.Where(x => x.Roles.Select(u => u.RoleId).Contains(role.Id)).ToList()
                        .OrderBy(x => x.SecondName).ThenBy(x => x.FirstName).ThenBy(x => x.Patronymic);
            var usersDto = _mapper.Map <List <UserDTO> >(users);

            return(usersDto);
        }
Exemplo n.º 3
0
        public ActionResult Profile(string id)
        {
            string userId;

            if (User.IsInRole(RoleDistributer.GetAdminRole()) && id != null)
            {
                userId = id;
            }
            else
            {
                userId = User.Identity.GetUserId();
            }
            var userDto       = _userService.GetById(userId);
            var userViewModel = _mapper.Map <UserViewModel>(userDto);

            if (User.IsInRole(RoleDistributer.GetStudentRole()) || User.IsInRole(RoleDistributer.GetBlockRole()) ||
                User.IsInRole(RoleDistributer.GetAdminRole()) &&
                User.Identity.GetUserId() != userId &&
                !_teacherService.IsTeacher(userId))
            {
                var notStartedCoursesDto       = _courseService.GetNotStartedCourses(userId);
                var notStartedCoursesViewModel = _mapper.Map <List <CourseViewModel> >(notStartedCoursesDto);

                var inProcessCoursesDto       = _courseService.GetInProcessCourses(userId);
                var inProcessCoursesViewModel = _mapper.Map <List <CourseViewModel> >(inProcessCoursesDto);

                var finishedCoursesDto       = _courseService.GetFinishedCourses(userId);
                var finishedCoursesViewModel = _mapper.Map <List <CourseViewModel> >(finishedCoursesDto);

                var profile = new ProfileCourseViewModel()
                {
                    UserViewModel     = userViewModel,
                    NotStartedCourses = notStartedCoursesViewModel,
                    InProcessCourses  = inProcessCoursesViewModel,
                    FinishedCourses   = finishedCoursesViewModel
                };
                return(View("StudentProfile", profile));
            }
            return(View(userViewModel));
        }
Exemplo n.º 4
0
 public void Unblock(string userId)
 {
     _database.UserManager.RemoveFromRole(userId, RoleDistributer.GetBlockRole());
     _database.UserManager.AddToRole(userId, RoleDistributer.GetStudentRole());
     _database.Save();
 }