Example #1
0
        public IActionResult View(int ID)
        {
            DetailHomeVM vm      = new DetailHomeVM();
            var          context = _courseService.GetContext();
            var          model   = from c in context.Courses
                                   join u in context.Users
                                   on c.UserId equals u.Id
                                   join cate in context.CourseCategories
                                   on c.CategoryId equals cate.Id
                                   where c.Id == ID
                                   select new DetailHomeVM
            {
                IdCourse        = c.Id,
                lstChapter      = (context.Chapter.Where(m => m.CourseId == ID).ToList()),
                lstCourseLesson = (context.Chapter
                                   .Join(context.CourseLessons,
                                         chap => chap.Id,
                                         cl => cl.ChapterId,
                                         (chap, cl) => new
                {
                    Chapter = chap,
                    CourseLessons = cl
                })
                                   .Where(m => m.Chapter.CourseId == ID)
                                   .Select(m => m.CourseLessons).ToList()),
                Name           = c.Name,
                NameCategory   = cate.Name,
                FullName       = u.FullName,
                UserId         = u.Id,
                PromotionPrice = c.PromotionPrice ?? 0,
                Price          = c.Price,
                Content        = c.Content,
                Image          = c.Image,
                Description    = c.Description
            };

            vm = model.FirstOrDefault();
            var lst = context.LessonComments.Where(m => m.LessonId == vm.lstCourseLesson[0].Id).Select(m => m).ToList();

            vm.lstComment = (from cm in lst
                             join u in context.Users
                             on cm.UserId equals u.Id
                             select new LessonCommentVM
            {
                FullName = u.FullName,
                Content = cm.Content,
                ImageUrl = u.ImageUrl
            }).ToList();
            return(View(vm));
        }
Example #2
0
        public IActionResult Detail(int ID)
        {
            DetailHomeVM vm      = new DetailHomeVM();
            var          context = _courseService.GetContext();
            var          model   = from c in context.Courses
                                   join u in context.Users
                                   on c.UserId equals u.Id
                                   join cate in context.CourseCategories
                                   on c.CategoryId equals cate.Id
                                   where c.Id == ID
                                   select new DetailHomeVM
            {
                IdCourse        = c.Id,
                lstChapter      = (context.Chapter.Where(m => m.CourseId == ID).ToList()),
                lstCourseLesson = (context.Chapter
                                   .Join(context.CourseLessons,
                                         chap => chap.Id,
                                         cl => cl.ChapterId,
                                         (chap, cl) => new
                {
                    Chapter = chap,
                    CourseLessons = cl
                })
                                   .Where(m => m.Chapter.CourseId == ID)
                                   .Select(m => m.CourseLessons).ToList()),
                Name           = c.Name,
                NameCategory   = cate.Name,
                FullName       = u.FullName,
                UserId         = u.Id,
                PromotionPrice = c.PromotionPrice ?? 0,
                Price          = c.Price,
                Content        = c.Content,
                Image          = c.Image,
                Description    = c.Description,
                IsFree         = c.IsFree ?? false
            };

            vm = model.FirstOrDefault();
            if (!vm.IsFree)
            {
                if (User.Identity.IsAuthenticated)
                {
                    ClaimsPrincipal currentUser     = this.User;
                    var             currentUserName = int.Parse(currentUser.FindFirst(ClaimTypes.NameIdentifier).Value);
                    var             _context        = _courseService.GetContext();
                    var             checkHasBuy     = (
                        from o in _context.Orders
                        join od in _context.OrderDetails
                        on o.Id equals od.OrderId
                        join u in _context.Users
                        on o.UserId equals u.Id
                        where u.Id == currentUserName &&
                        od.CourseId == vm.IdCourse &&
                        o.Status == OrderStatus.Paid
                        select od
                        ).Count();
                    vm.HasBuy = checkHasBuy > 0 ? true : false;
                }
                else
                {
                    vm.HasBuy = false;
                }
            }
            return(View(vm));
        }