public virtual async Task <CourseLesson> InsertCourseLessonModel(CourseLessonModel model)
        {
            var lesson = model.ToEntity();
            await _courseLessonService.Insert(lesson);

            //activity log
            await _customerActivityService.InsertActivity("AddNewCourseLesson", lesson.Id, _localizationService.GetResource("ActivityLog.AddNewCourseLesson"), lesson.Name);

            return(lesson);
        }
Beispiel #2
0
        public async Task <IActionResult> EditLesson(CourseLessonModel model, bool continueEditing)
        {
            var lesson = await _courseLessonService.GetById(model.Id);

            if (lesson == null)
            {
                //No lesson found with the specified id
                return(RedirectToAction("List"));
            }

            var course = await _courseService.GetById(model.CourseId);

            if (course == null)
            {
                //No category found with the specified id
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentCustomer.IsStaff())
            {
                if (!course.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId))
                {
                    return(RedirectToAction("Edit", new { id = course.Id }));
                }
            }
            if (ModelState.IsValid)
            {
                lesson = await _courseViewModelService.UpdateCourseLessonModel(lesson, model);

                SuccessNotification(_localizationService.GetResource("Admin.Courses.Course.Lesson.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    await SaveSelectedTabIndex();

                    return(RedirectToAction("EditLesson", new { id = lesson.Id }));
                }
                return(RedirectToAction("Edit", new { id = course.Id }));
            }
            //If we got this far, something failed, redisplay form
            model = await _courseViewModelService.PrepareCourseLessonModel(lesson.CourseId, model);

            return(View(model));
        }
        public virtual async Task <CourseLessonModel> PrepareCourseLessonModel(string courseId, CourseLessonModel model = null)
        {
            if (model == null)
            {
                model           = new CourseLessonModel();
                model.Published = true;
            }
            model.CourseId = courseId;

            foreach (var item in await _courseSubjectService.GetByCourseId(courseId))
            {
                model.AvailableSubjects.Add(new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem()
                {
                    Text  = item.Name,
                    Value = item.Id
                });
            }

            return(model);
        }
Beispiel #4
0
        public async Task <IActionResult> CreateLesson(CourseLessonModel model, bool continueEditing)
        {
            var course = await _courseService.GetById(model.CourseId);

            if (course == null)
            {
                //No course found with the specified id
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentCustomer.IsStaff())
            {
                if (!course.LimitedToStores || (course.LimitedToStores && course.Stores.Contains(_workContext.CurrentCustomer.StaffStoreId) && course.Stores.Count > 1))
                {
                    WarningNotification(_localizationService.GetResource("Admin.Courses.Course.Permisions"));
                }
                else
                {
                    if (!course.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId))
                    {
                        return(RedirectToAction("List"));
                    }
                }
            }

            if (ModelState.IsValid)
            {
                var lesson = await _courseViewModelService.InsertCourseLessonModel(model);

                SuccessNotification(_localizationService.GetResource("Admin.Courses.Course.Lesson.Added"));
                return(continueEditing ? RedirectToAction("EditLesson", new { id = lesson.Id }) : RedirectToAction("Edit", new { Id = lesson.CourseId }));
            }

            //If we got this far, something failed, redisplay form
            model = await _courseViewModelService.PrepareCourseLessonModel(model.CourseId, model);

            return(View(model));
        }
        public virtual async Task <CourseLesson> UpdateCourseLessonModel(CourseLesson lesson, CourseLessonModel model)
        {
            string prevPictureId = lesson.PictureId;

            lesson = model.ToEntity(lesson);
            await _courseLessonService.Update(lesson);

            //delete an old picture (if deleted or updated)
            if (!string.IsNullOrEmpty(prevPictureId) && prevPictureId != lesson.PictureId)
            {
                var prevPicture = await _pictureService.GetPictureById(prevPictureId);

                if (prevPicture != null)
                {
                    await _pictureService.DeletePicture(prevPicture);
                }
            }

            //activity log
            await _customerActivityService.InsertActivity("EditCourseLesson", lesson.Id, _localizationService.GetResource("ActivityLog.EditLessonCourse"), lesson.Name);

            return(lesson);
        }
 public static CourseLesson ToEntity(this CourseLessonModel model, CourseLesson destination)
 {
     return(model.MapTo(destination));
 }
 public static CourseLesson ToEntity(this CourseLessonModel model)
 {
     return(model.MapTo <CourseLessonModel, CourseLesson>());
 }