Пример #1
0
        public ActionResult Index(string order = "asc", string teacherSortId = "all", int subjectSortId = 0)
        {
            var coursesDto = _courseService.GetCourses(order, teacherSortId, subjectSortId);

            if (!User.Identity.IsAuthenticated)
            {
                coursesDto = _courseService.GetNotStartedCourses(coursesDto);
            }
            if (User.IsInRole(RoleDistributer.GetStudentRole()))
            {
                coursesDto = _courseService.CheckSubscribe(User.Identity.GetUserId(), coursesDto);
                coursesDto = _courseService.GetNotStartedCourses(coursesDto);
            }
            var coursesViewModel = _mapper.Map <List <CourseViewModel> >(coursesDto);
            SortCoursesPanelViewModel sortCoursesPanelViewModel = new SortCoursesPanelViewModel()
            {
                OrderParams       = _courseService.GetParametersAsListForFilter().ToList(),
                SubjectSortParams = _subjectService.GetSubjectsAsListForFilter().ToList(),
                TeacherSortParams = _teacherService.GetTeachersAsListForFilter().ToList()
            };
            var coursesList = new CourseListViewModel()
            {
                Course         = new CourseViewModel(),
                Courses        = coursesViewModel,
                PanelViewModel = sortCoursesPanelViewModel
            };

            if (User.IsInRole(RoleDistributer.GetAdminRole()))
            {
                return(View("AdminIndex", coursesList));
            }
            return(View("StudentIndex", coursesList));
        }
Пример #2
0
        public FileContentResult UserPhoto(string id)
        {
            string userId;

            if (User.IsInRole(RoleDistributer.GetAdminRole()) && id != null)
            {
                userId = id;
            }
            else
            {
                userId = User.Identity.GetUserId();
            }

            var userDto = _userService.GetById(userId);

            if (userDto.Photo.Length == 0)
            {
                string fileName = HttpContext.Server.MapPath(@"~/Content/Images/noImage.png");

                byte[]       imageData       = null;
                FileInfo     fileInfo        = new FileInfo(fileName);
                long         imageFileLength = fileInfo.Length;
                FileStream   fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                imageData = br.ReadBytes((int)imageFileLength);

                return(File(imageData, "image/png"));
            }
            else
            {
                return(new FileContentResult(userDto.Photo, "image/jpeg"));
            }
        }
Пример #3
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()));
        }
Пример #4
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));
        }