public LecturesDataViewModel(Lectures lectures) { Theme = lectures.Theme; LecturesId = lectures.Id; Duration = lectures.Duration; SubjectId = lectures.SubjectId; Order = lectures.Order; PathFile = lectures.Attachments; Attachments = FilesManagementService.GetAttachments(lectures.Attachments); }
public Lectures SaveLectures(Lectures lectures, IList<Attachment> attachments, Int32 userId) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { if (!string.IsNullOrEmpty(lectures.Attachments)) { var deleteFiles = repositoriesContainer.AttachmentRepository.GetAll( new Query<Attachment>(e => e.PathName == lectures.Attachments)).ToList().Where(e => attachments.All(x => x.Id != e.Id)).ToList(); foreach (var attachment in deleteFiles) { FilesManagementService.DeleteFileAttachment(attachment); } } else { lectures.Attachments = GetGuidFileName(); } FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), lectures.Attachments); foreach (var attachment in attachments) { if (attachment.Id == 0) { attachment.PathName = lectures.Attachments; repositoriesContainer.AttachmentRepository.Save(attachment); } } repositoriesContainer.LecturesRepository.Save(lectures); repositoriesContainer.ApplyChanges(); if (lectures.IsNew && lectures.Subject.SubjectModules.Any(s => s.Module.ModuleType == ModuleType.Lectures)) ConceptManagementService.AttachFolderToLectSection(lectures.Theme, userId, lectures.SubjectId); } return lectures; }
public void DeleteLection(Lectures lectures) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { var lectModel = repositoriesContainer.LecturesRepository.GetBy(new Query<Lectures>(e => e.Id == lectures.Id)); var deleteFiles = repositoriesContainer.AttachmentRepository.GetAll( new Query<Attachment>(e => e.PathName == lectModel.Attachments)).ToList(); foreach (var attachment in deleteFiles) { FilesManagementService.DeleteFileAttachment(attachment); } repositoriesContainer.SubjectRepository.DeleteLection(lectures); repositoriesContainer.ApplyChanges(); } }