Example #1
0
        public IActionResult Index()
        {
            var user = _userService.GetUser(User.Identity.Name);
            StudentViewModel model = new StudentViewModel()
            {
                Name     = user.Name,
                SurrName = user.Surrname,
                Courses  = new List <Course>()
            };

            var courses = _courseService.GetCoursesForUser(user.Id);

            foreach (var item in courses)
            {
                Course course = new Course()
                {
                    CourseName = item.Title
                };
                course.Rate = _ratingsService.GetRaitingsForUser(user.Id, item.Id)
                              .Select(x => x.Grade)
                              .ToList();
                if (course.Rate.Count() > 0)
                {
                    course.AverageRate = course.Rate.Average();
                }

                model.Courses.Add(course);
            }


            return(View(model));
        }
Example #2
0
        public IActionResult AddRate(string Id, int IdCourse)
        {
            var user   = _userService.GetUserId(Id);
            var course = _courseService.GetCourse(IdCourse);

            if (user != null && course != null)
            {
                UserRateViewModel model = new UserRateViewModel()
                {
                    Name       = user.Name,
                    CourseId   = course.Id,
                    SurrName   = user.Surrname,
                    UserId     = user.Id,
                    CourseName = course.Title,
                    AddRate    = 5
                };
                model.Rate = _ratingsService.GetRaitingsForUser(user.Id, course.Id)
                             .Select(x => x.Grade);
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }