public LessonBO UploadFile(IFormFile file, int courseId, IProgress <UploadProgress> progress, int jobId, string ftpFileName, int idFromJwt) { using (var uow = _facade.UnitOfWork) { var course = uow.CourseRepo.Get(courseId); if (course.CreatorId != idFromJwt) { return(null); } // generate filename // upload file string fileName = file.FileName; string fullFileName = _fileHanlder.UploadFile(file, progress, jobId, ftpFileName); if (fullFileName != null) { // create and return material object on success var lesson = new Lesson() { VideoId = fullFileName, Title = fileName, Course = course, }; course.Lessons.Add(lesson); uow.Complete(); return(_lesConv.Convert(lesson)); } else { return(null); } } }
private List <Section> ConvertSections(List <SectionBO> sectionsToConvert) { var sectionsConverted = new List <Section>(); foreach (var section in sectionsToConvert) { var lessonsConverted = new List <Lesson>(); foreach (var lesson in section.Lessons) { var lessonConverted = _lesConv.Convert(lesson); lessonsConverted.Add(lessonConverted); } var sectionConverted = _secConverter.Convert(section); sectionConverted.Lessons = lessonsConverted; sectionsConverted.Add(sectionConverted); } return(sectionsConverted); }
public LessonBO Create(LessonBO lesson) { using (var uow = _facade.UnitOfWork) { // TODO check if entity is valid, and throw errors if not var lessonCreated = uow.LessonRepo.Create(_lessonConv.Convert(lesson)); uow.Complete(); return(_lessonConv.Convert(lessonCreated)); } }
public SectionBO Get(int id) { using (var uow = _facade.UnitOfWork) { SectionBO section = null; var secFromDb = uow.SectionRepo.Get(id); if (secFromDb != null) { var convCourse = _crsConv.Convert(secFromDb.Course); var convLessons = secFromDb.Lessons?.Select(l => _lesConv.Convert(l)).ToList(); section = _sectionConv.Convert(secFromDb); section.Course = convCourse; section.Lessons = convLessons; /*section.Lessons = uow.LessonRepo.GetAllById(section.LessonIds) * .Select(l => _lesConv.Convert(l)) * .ToList();*/ } uow.Complete(); return(section); } }