public JsonResult GetById([FromForm] int courseId) { DataResult dr = new DataResult(); try { CourseBLL courseBLL = new CourseBLL(); CourseEntity courseEntity = courseBLL.GetById(courseId); courseEntity.videoUrl = ""; TeacherBLL teacherBLL = new TeacherBLL(); courseEntity.teacherEntity = teacherBLL.GetById(courseEntity.teacherId); CourseOrderBLL courseOrderBLL = new CourseOrderBLL(); courseEntity.countSold = courseOrderBLL.GetCountByCourseId(courseEntity.courseId); dr.code = "200"; dr.data = courseEntity; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public JsonResult PageList([FromForm] string token, [FromForm] int courseTypeId = -1, [FromForm] int pageNumber = 1, [FromForm] int pageSize = 10) { DataResult dr = new DataResult(); try { CourseBLL courseBLL = new CourseBLL(); int totalItemCount = courseBLL.Count(courseTypeId); List <CourseEntity> courseEntities = courseBLL.List(courseTypeId, pageNumber: pageNumber, pageSize: pageSize, totalCount: totalItemCount); if (courseEntities.Count > 0) { CourseOrderBLL courseOrderBLL = new CourseOrderBLL(); courseEntities.ForEach(it => { it.countSold = courseOrderBLL.GetCountByCourseId(it.courseId); }); } PageData pageData = new PageData(courseEntities, pageNumber, pageSize, totalItemCount); dr.code = "200"; dr.data = pageData; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public JsonResult List([FromForm] string token) { DataResult dr = new DataResult(); try { CourseRecommendBLL courseRecommendBLL = new CourseRecommendBLL(); CourseBLL courseBLL = new CourseBLL(); CourseOrderBLL courseOrderBLL = new CourseOrderBLL(); List <CourseRecommendEntity> courseRecommendEntities = courseRecommendBLL.ActionDal.ActionDBAccess.Queryable <CourseRecommendEntity>().ToList(); courseRecommendEntities.ForEach(it => { List <int> vs = courseRecommendBLL.ActionDal.ActionDBAccess.Queryable <CourseRecommendCorrelationEntity>() .Where(itt => itt.courseRecommendId == it.courseRecommendId) .Select(itt => itt.courseId) .ToList(); if (vs.Count > 0) { it.courseEntities = courseBLL.ListByIdInts(vs); } if (it.courseEntities.Count > 0) { it.courseEntities.ForEach(i => { i.countSold = courseOrderBLL.GetCountByCourseId(i.courseId); }); } }); dr.code = "200"; dr.data = courseRecommendEntities; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }
public JsonResult GetDetailById([FromForm] string token, [FromForm] int courseId) { DataResult dr = new DataResult(); try { UserEntity userEntity = this.GetUserByToken(token); CourseOrderBLL courseOrderBLL = new CourseOrderBLL(); CourseOrderEntity courseOrderEntity = courseOrderBLL.GetByCourseAndUserId(courseId, userEntity.userId); if (courseOrderEntity == null) { dr.code = "201"; dr.msg = "未购买该课程"; return(Json(dr)); } CourseBLL courseBLL = new CourseBLL(); CourseEntity courseEntity = courseBLL.GetById(courseId); CourseSectionBLL courseSectionBLL = new CourseSectionBLL(); courseEntity.courseSectionEntities = courseSectionBLL.ListByCourseId(courseId); TeacherBLL teacherBLL = new TeacherBLL(); courseEntity.teacherEntity = teacherBLL.GetById(courseEntity.teacherId); courseEntity.countSold = courseOrderBLL.GetCountByCourseId(courseEntity.courseId); dr.code = "200"; dr.data = courseEntity; } catch (Exception ex) { dr.code = "999"; dr.msg = ex.Message; } return(Json(dr)); }