public async Task <Stream> GetDocumentVersionAsync(DocumentVersionEntity verEntity) { var stor = _config.Stors.First(s => s.ShortName == verEntity.StorName).GetStorFromConfig(); var fileName = verEntity.GetServerFileName(); var stream = await stor.GetFileAsync(fileName); return(stream); }
public async Task CreateDocumentVersion(string userName, DocumentVersion documentVersion, FileBlob fileBlob) { try { DocumentEntity documentEntity = _documentRepository .Get(e => e.Id == documentVersion.Document.Id) .FirstOrDefault(e => e.Reviewers.Any(u => u.UserName == userName)); if (documentEntity == null) { throw new DocManagerException("Requested document does not exist or not accessible."); } //DocumentEntity document = _documentRepository // .Get(e => e.Id == documentVersion.Document.Id) // .FirstOrDefault(); //if (document?.Status.Name != "Approved") //{ // throw new DocManagerException("You cannot add new version for document in review status."); //} DocumentVersionEntity documentVersionEntity = Mapper.Map <DocumentVersion, DocumentVersionEntity>(documentVersion); FileBlobEntity fileBlobEntity = Mapper.Map <FileBlob, FileBlobEntity>(fileBlob); _fileBlobRepository.Add(fileBlobEntity); documentVersionEntity.FileBlob = fileBlobEntity; _documentVersionRepository.Add(documentVersionEntity); await _documentVersionRepository.CommitAsync(); } catch (Exception e) { throw new DocManagerException( "Error during document version creation.", e.Message, e); } }
public void Decline(string selfUserName, int documentId) { DocumentEntity documentEntity = _documentRepository .Get(e => e.Id == documentId) .FirstOrDefault(e => e.Reviewers.Any(u => u.UserName == selfUserName)); if (documentEntity == null) { throw new DocManagerException("Requested document does not exist or not accessible."); } DocumentEntity document = _documentRepository .Get(e => e.Id == documentId) .FirstOrDefault(); if (document?.Status.Name != "Need review") { throw new DocManagerException("You cannot modify document in approved status."); } StatusEntity statusEntity = _statusRepository .GetAll() .AsNoTracking() .FirstOrDefault(s => s.Name == "Approved"); document.Status = statusEntity; DocumentVersionEntity last = document.DocumentVersions.Last(); document.DocumentVersions = document.DocumentVersions .Except(new [] { last }) .ToList(); _documentVersionRepository.Delete(last); _documentRepository.CommitAsync(); }
public async Task MoveDocumentVersion(DocumentVersionEntity verEntity, string newStorProvider) { try { IStor origStor = _config.Stors.First(s => s.ShortName == verEntity.StorName).GetStorFromConfig(); IStor newStor = _config.Stors.First(s => s.ShortName == newStorProvider).GetStorFromConfig(); if (String.IsNullOrWhiteSpace(origStor.ShortName)) { throw new Exception("Unable to find old stor within config"); } if (String.IsNullOrWhiteSpace(newStor.ShortName)) { throw new Exception("Unable to find new stor within config"); } var fileName = verEntity.GetServerFileName(); string hash; using (var origStream = await origStor.GetFileAsync(fileName)) { await newStor.SetFileAsync(fileName, origStream); hash = await newStor.GetFileHashAsync(fileName); if (hash != verEntity.MD5Hash) { await newStor.RemoveFileAsync(fileName); throw new Exception("File transfer failed MD5 hash is not equal"); } } await origStor.RemoveFileAsync(fileName); } catch (Exception ex) { throw new Exception("Unable to move document see inner exception", ex); } }
public async Task <IActionResult> Put(int id, [FromBody] Stream value) { var currentUser = HttpContext.User.Identity.Name; //uploading a new version of the document var meta = _metadataRepository.GetById(id, true, false); if (meta == null) { return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentUpdate, "Document", id.ToString())); } if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Update, meta.BuisnessArea)) { return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentUpdate, "Document", id.ToString())); } if (meta.Locked.Is && meta.Locked.By != currentUser) { return(_securityRepository.GateDocumentLockedByAnotherUser(currentUser, "Document", id.ToString())); } meta.Versions.Add(DocumentVersionEntity.FromMetadata(meta)); meta.Version++; await _documentRepository.SetDocumentAsync(meta, value); _logger.Log(LogLevel.Debug, "Uploaded New Document Version {0} for User {1}", meta.Id, HttpContext.User.Identity.Name); _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentUpdate, id, "Document", true); _metadataRepository.Edit(meta); _metadataRepository.SaveChanges(); return(Ok()); }
public async Task DeleteDocumentVersionAsync(DocumentVersionEntity verEntity) { IStor stor = _config.Stors.First(s => s.ShortName == verEntity.StorName).GetStorFromConfig(); var fileName = verEntity.GetServerFileName(); await stor.RemoveFileAsync(fileName); }
public void DeleteVersion(DocumentVersionEntity entity) { _context.DocumentVersions.Remove(entity); }
public static string GetServerFileName(this DocumentVersionEntity versionEntity) { return(string.Format("{0}.v{1}.{2}.{3}", versionEntity.DocumentId.ToString(), versionEntity.Version.ToString(), versionEntity.Name, versionEntity.Extension)); }