コード例 #1
0
        // GET: /Course/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            Course course = this.Data.Courses.All().Where(c => c.Id == id).FirstOrDefault();

            if (course == null)
            {
                return HttpNotFound();
            }

            PublicCourseModel courseModel = new PublicCourseModel()
            {
                Description = course.Description,
                Id = course.Id,
                LecturerName = course.Lecturer,
                Title = course.Title,
                EnrolledCount = this.Data.CourseInstances
                                    .All(new string[] { "Course" })
                                    .Where(c => c.Course.Id == id)
                                    .Count()
            };

            string loggedUserId = GetLoggedUserId();

            if (loggedUserId != null)
            {
                courseModel.Enrolled = this.Data.CourseInstances
                                        .All(new string[] { "User", "Course" })
                                        .Where(c => c.User.Id == loggedUserId)
                                        .Where(c => c.Course.Id == course.Id)
                                        .Count() == 1;
            }

            return View(courseModel);
        }
コード例 #2
0
        public ActionResult ShowCourseDetails(string bookName,int id)
        {
            var course = this.Data.Courses.GetById(id);
            PublicCourseModel courseModel = new PublicCourseModel()
            {
                Description = course.Description,
                Id = course.Id,
                LecturerName = course.Lecturer,
                Title = course.Title
            };

            return View(courseModel);
        }