diff --git a/.DS_Store b/.DS_Store index 2d4dcb3..b8a0dd0 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..4757b0d Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/Plugins/.DS_Store b/src/Plugins/.DS_Store new file mode 100644 index 0000000..9a167f1 Binary files /dev/null and b/src/Plugins/.DS_Store differ diff --git a/src/Plugins/Nop.Plugin.Misc.SimpleLMS/.DS_Store b/src/Plugins/Nop.Plugin.Misc.SimpleLMS/.DS_Store new file mode 100644 index 0000000..94fa4fe Binary files /dev/null and b/src/Plugins/Nop.Plugin.Misc.SimpleLMS/.DS_Store differ diff --git a/src/Plugins/Nop.Plugin.Misc.SimpleLMS/Areas/Admin/.DS_Store b/src/Plugins/Nop.Plugin.Misc.SimpleLMS/Areas/Admin/.DS_Store new file mode 100644 index 0000000..3feeae5 Binary files /dev/null and b/src/Plugins/Nop.Plugin.Misc.SimpleLMS/Areas/Admin/.DS_Store differ diff --git a/src/Plugins/Nop.Plugin.Misc.SimpleLMS/Areas/Admin/Controllers/CourseController.cs b/src/Plugins/Nop.Plugin.Misc.SimpleLMS/Areas/Admin/Controllers/CourseController.cs new file mode 100755 index 0000000..b2f9fd8 --- /dev/null +++ b/src/Plugins/Nop.Plugin.Misc.SimpleLMS/Areas/Admin/Controllers/CourseController.cs @@ -0,0 +1,857 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +//using System.Web.Mvc; +using Microsoft.AspNetCore.Mvc; +using Nop.Core; +using Nop.Plugin.Misc.SimpleLMS.Areas.Admin.Factories; +using Nop.Plugin.Misc.SimpleLMS.Areas.Admin.Models; +using Nop.Plugin.Misc.SimpleLMS.Domains; +using Nop.Plugin.Misc.SimpleLMS.Services; +using Nop.Services.Customers; +using Nop.Services.Localization; +using Nop.Services.Logging; +using Nop.Services.Messages; +using Nop.Services.Security; +using Nop.Web.Areas.Admin.Controllers; +using Nop.Web.Areas.Admin.Infrastructure.Mapper.Extensions; +using Nop.Web.Framework.Mvc.Filters; + +namespace Nop.Plugin.Misc.SimpleLMS.Areas.Admin.Controllers +{ + public partial class CourseController : BaseAdminController + { + private readonly IWorkContext _workContext; + private readonly IPermissionService _permissionService; + private readonly ILocalizationService _localizationService; + private readonly ICustomerActivityService _customerActivityService; + private readonly AdminCourseModelFactory _courseModelFactory; + private readonly CourseService _courseService; + private readonly INotificationService _notificationService; + + public CourseController(IPermissionService permissionService + , ILocalizationService localizationService + , ICustomerActivityService customerActivityService + , ICustomerService customerService + , AdminCourseModelFactory courseModelFactory + , CourseService courseService + , INotificationService notificationService + , IWorkContext workContext) + { + _permissionService = permissionService; + _localizationService = localizationService; + _customerActivityService = customerActivityService; + _courseModelFactory = courseModelFactory; + _courseService = courseService; + _notificationService = notificationService; + _workContext = workContext; + } + + public virtual IActionResult Index() + { + return RedirectToAction("List"); + } + + public virtual async Task List() + { + if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) + return AccessDeniedView(); + + var courseSearchModel = new CourseSearchModel(); + + //prepare model + var model = await _courseModelFactory.PrepareCourseSearchModelAsync(courseSearchModel); + + return View("~/Plugins/Misc.SimpleLMS/Areas/Admin/Views/Course/List.cshtml", model); + } + + [HttpPost] + public virtual async Task CourseList(CourseSearchModel searchModel) + { + if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) + return await AccessDeniedDataTablesJson(); + + var customer = await _workContext.GetCurrentCustomerAsync(); + + searchModel.InstructorGUID = customer.CustomerGuid.ToString(); + + //prepare model + var model = await _courseModelFactory.PrepareCourseListModelAsync(searchModel); + + return Json(model); + } + + + public virtual async Task Create() + { + if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) + return AccessDeniedView(); + + var model = await _courseModelFactory.PrepareCourseModelAsync(new CourseModel(), null); + + return View("~/Plugins/Misc.SimpleLMS/Areas/Admin/Views/Course/Create.cshtml", model); + } + + public virtual async Task Sections(int courseId) + { + if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) + return AccessDeniedView(); + + var courseExisting = await _courseService.GetCourseById(courseId); + var customer = await _workContext.GetCurrentCustomerAsync(); + + if (courseExisting.InstructorGuid != customer.CustomerGuid) + return await AccessDeniedDataTablesJson(); + + + + var model = await _courseModelFactory.PrepareCourseModelAsync(new CourseModel(), courseExisting); + + return PartialView("~/Plugins/Misc.SimpleLMS/Areas/Admin/Views/Course/_CreateOrUpdate.Sections.cshtml", model.Sections); + } + + [HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")] + [ValidateAntiForgeryToken] + public virtual async Task Create(CourseModel model, bool continueEditing) + { + if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageProducts)) + return AccessDeniedView(); + + if (ModelState.IsValid) + { + var customer = await _workContext.GetCurrentCustomerAsync(); + var course = model.ToEntity(); + + course.InstructorId = customer.Id; + course.InstructorGuid = customer.CustomerGuid; + course.CreatedOnUtc = DateTime.UtcNow; + course.UpdatedOnUtc = DateTime.UtcNow; + + await _courseService.InsertOrUpdateCourseAsync(course); + + //foreach (var sectionModel in model.Sections) + //{ + // var section = sectionModel.ToEntity
(); + // section.CourseId = course.Id; + // await _courseService.InsertOrUpdateSectionAsync(section); + // foreach (var lessonModel in sectionModel.Lessons) + // { + // var lesson = lessonModel.ToEntity(); + // await _courseService.InsertOrUpdateLessonAsync(lesson); + // await _courseService.InsertOrUpdateSectionLessonAsync(new SectionLesson + // { + // CourseId = course.Id, + // DisplayOrder = lessonModel.DisplayOrder, + // LessonId = lesson.Id, + // IsFreeLesson = lessonModel.IsFreeLesson, + // SectionId = section.Id + // }); + + // if (lessonModel.LessonType == LessonType.Document) + // { + // foreach (var attachmentModel in lessonModel.Attachments) + // { + // var attachment = attachmentModel.ToEntity(); + // attachment.InstructorId = customer.Id; + // attachment.InstructorGuid = customer.CustomerGuid; + // await _courseService.InsertOrUpdateAttachmentAsync(attachment); + // await _courseService.InsertOrUpdateLessonAttachmentAsync(new LessonAttachment + // { + // AttachmentId = attachment.Id, + // LessonId = lesson.Id + // }); + // } + // } + // else if (lessonModel.LessonType == LessonType.Video) + // { + // if (lessonModel.Video != null) + // { + // var video = lessonModel.Video.ToEntity