Ejemplo n.º 1
0
        public IActionResult Edit(string ID)
        {
            DefaultModel model = new DefaultModel
            {
                ID = ID
            };

            ViewBag.Title = "Cập nhật thông tin";
            if (string.IsNullOrEmpty(ID))
            {
                return(RedirectToAction("Create"));
            }
            else
            {
                var item        = _service.GetByID(ID);
                var subjectdata = _subjectService.Find(true, o => o.IsActive).OrderBy(o => o.Name).ToList();
                ViewBag.SubjectData = subjectdata;

                var gradedata = _gradeService.Find(true, o => o.IsActive).OrderBy(o => o.Name).ToList();
                ViewBag.GradeData = gradedata;

                if (item == null)
                {
                    SetMessageError("Không tìm thấy đối tượng");
                }
                ViewBag.Data = item;
            }
            return(View());
        }
        public IActionResult Detail(string ID)
        {
            DefaultModel model = new DefaultModel
            {
                ID = ID
            };

            ViewBag.Title = "";
            if (string.IsNullOrEmpty(ID))
            {
                return(RedirectToAction("Create"));
            }
            else
            {
                var item = _service.GetByID(ID);

                if (item == null)
                {
                    SetMessageError("Không tìm thấy đối tượng");
                }
                ViewBag.Title  = item.Name;
                ViewBag.Course = item;
                var lessonsCourse = _lessonService.CreateQuery().Find(o => o.CreateUser == _currentUser.ID && o.IsParentCourse == true && o.CourseID == item.ID).ToList();
                ViewBag.LessonCourse = lessonsCourse;
                ViewBag.Data         = new ModCourseViewModel(item)
                {
                    Program    = _programService.GetByID(item.ProgramID),
                    Grade      = _gradeService.GetByID(item.GradeID),
                    Subject    = _subjectService.GetByID(item.SubjectID),
                    ListLesson = lessonsCourse
                };
                var chapters = _chapterService.Find(true, o => o.CourseID == item.ID);
                ViewBag.Chapters = chapters.Select(o => new ModChapterViewModel(o)
                {
                    Parent = (!string.IsNullOrEmpty(o.ParentID) && o.ParentID != "0")
                        ? chapters.FirstOrDefault(t => t.ID == o.ParentID)
                        : new ModChapterEntity {
                        Order = o.Order
                    },
                    ChildNode = _chapterService.CreateQuery().Find(x => x.ParentID == ID).ToList(),
                    ItemChild = _lessonService.CreateQuery().Find(x => x.IsParentCourse == false && x.ChapterID == ID).ToList()
                }).OrderBy(o => o.Parent.Order).ThenBy(o => o.Order).ToList();
            }
            return(View());
        }