コード例 #1
0
        public IActionResult UploadContent(int id)
        {
            var course = _courseData.GetFullCourse(id);


            var courseTaskViewModel = new List <CourseTaskViewModel>();

            foreach (var section in course.Sections)
            {
                foreach (var sectionTopic in section.Topics)
                {
                    foreach (var sectionTopicVideoTask in sectionTopic.VideoTasks)
                    {
                        courseTaskViewModel.Add(new CourseTaskViewModel
                        {
                            VideoExist  = !string.IsNullOrEmpty(sectionTopicVideoTask.VideoUrl),
                            TopicName   = sectionTopic.Name,
                            TaskName    = sectionTopicVideoTask.Name,
                            VideoTaskId = sectionTopicVideoTask.Id,
                            CourseId    = course.Id
                        });
                    }
                }
            }
            var model = new UploadContentViewModel
            {
                CourseId    = course.Id,
                Models      = courseTaskViewModel,
                CourseImage = course.ImageUrl
            };

            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> UploadCourseImage(UploadCourseCover model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var course = _courseData.GetFullCourse(model.CourseId);

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

            string path = _hostingEnv.WebRootPath +
                          $"{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}coursesMainImages{Path.DirectorySeparatorChar}" +
                          model.File.FileName;

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                await model.File.CopyToAsync(fileStream);
            }


            var urlPath = $"/images/coursesMainImages/{model.File.FileName}";

            course.ImageUrl      = urlPath;
            course.LocalImageUrl = path;
            _courseData.UpdateCourse(course);
            return(Ok(new { ImageUrl = urlPath }));
        }
コード例 #3
0
        public async Task <IViewComponentResult> InvokeAsync(int idOfCourse)
        {
            var viewSections = new List <SectionViewModel>();
            var course       = _courseData.GetFullCourse(idOfCourse);

            foreach (var section in course.Sections)
            {
                var topics           = new List <SectionViewModel>();
                var sectionViewModel = new SectionViewModel
                {
                    ParentSection = null,
                    Name          = section.Name,
                    Id            = section.Id,
                    ChildSections = null
                };
                foreach (var topic in section.Topics)
                {
                    topics.Add(new SectionViewModel
                    {
                        ParentSection = sectionViewModel,
                        Name          = topic.Name,
                        Id            = topic.Id
                    });
                }
                sectionViewModel.ChildSections = topics;
                viewSections.Add(sectionViewModel);
            }

            return(View(viewSections));
        }
コード例 #4
0
        public IActionResult DeleteCourse(int id)
        {
            var course = _data.GetFullCourse(id);

            _data.DeleteCourse(course);
            return(Ok());
        }
コード例 #5
0
        public async Task <IActionResult> AddCourse(int courseId)
        {
            var course = _data.GetFullCourse(courseId);

            var userId = User.GetUserId();

            var user = _userData.GetUserWithStats(userId);


            user.CourseStatistics.Add(CreateStatisticsForCourse(course));

            _userData.UpdateUser(user);

            _userData.AddCourseToUser(course, user);


            return(RedirectToAction("Details", "Course", new { id = courseId }));
        }
コード例 #6
0
        public IActionResult Details(int id)
        {
            var course = _courseData.GetFullCourse(id);

            return(View(course));
        }
コード例 #7
0
 public IActionResult GetCourses()
 {
     return(Ok(_data.GetFullCourse().Select(c => _mapper.Map <Course, CourseDto>(c))));
 }
コード例 #8
0
        public IActionResult Course(int id)
        {
            var course = _data.GetFullCourse(id);

            return(View(course));
        }