public PracticalsViewData(Practical practical) { Theme = practical.Theme; PracticalId = practical.Id; Duration = practical.Duration; SubjectId = practical.SubjectId; Order = practical.Order; PathFile = practical.Attachments; ShortName = practical.ShortName; Attachments = FilesManagementService.GetAttachments(practical.Attachments); }
public Practical SavePractical(Practical practical, IList<Attachment> attachments, Int32 userId) { using (var repositoriesContainer = new LmPlatformRepositoriesContainer()) { if (!string.IsNullOrEmpty(practical.Attachments)) { var deleteFiles = repositoriesContainer.AttachmentRepository.GetAll( new Query<Attachment>(e => e.PathName == practical.Attachments)).ToList().Where(e => attachments.All(x => x.Id != e.Id)).ToList(); foreach (var attachment in deleteFiles) { FilesManagementService.DeleteFileAttachment(attachment); } } else { practical.Attachments = GetGuidFileName(); } FilesManagementService.SaveFiles(attachments.Where(e => e.Id == 0), practical.Attachments); foreach (var attachment in attachments) { if (attachment.Id == 0) { attachment.PathName = practical.Attachments; repositoriesContainer.AttachmentRepository.Save(attachment); } } repositoriesContainer.PracticalRepository.Save(practical); repositoriesContainer.ApplyChanges(); if (practical.IsNew && practical.Subject.SubjectModules.Any(m => m.Module.ModuleType == ModuleType.Practical)) ConceptManagementService.AttachFolderToLabSection(practical.Theme, userId, practical.SubjectId); } return practical; }