Ejemplo n.º 1
0
        public IActionResult Browse()
        {
            ActionResult result = null;
            int          _role  = 0;

            if (IsAuthenticated)
            {
                _role = CurrentUser.RoleId;
                if (_role == 2)
                {
                    List <Course>   courses    = (List <Course>)_coursedb.GetCourses();
                    BrowseViewModel courseList = new BrowseViewModel()
                    {
                        BrowseStudentId   = CurrentUser.Id,
                        BrowseStudentName = CurrentUser.FirstName
                    };
                    foreach (Course entry in courses)
                    {
                        BrowseModel viewCourse = new BrowseModel()
                        {
                            Id                = entry.Id,
                            Name              = entry.Name,
                            TeacherName       = entry.TeacherFirstName + " " + entry.TeacherLastName,
                            EstimatedDuration = entry.EstimatedDuration,
                            Image             = entry.Image,
                            CourseRating      = _coursedb.CourseRating(entry.Id)
                        };
                        courseList.BrowseCourseList.Add(viewCourse);
                    }
                    result = View(courseList);
                }
                else
                {
                    result = RedirectToAction("Dashboard", "Teacher");
                }
            }
            else
            {
                result = RedirectToAction("Login", "User");
            }
            return(result);
        }