public IActionResult DownloadFile(string fileId) { var file = _documentService.GetDocumentByIdAsync(fileId); string physical_path = _pProvider.ContentPath() + "\\" + file.Result.OwnerId + "\\" + file.Result.DocumentId; if (file.Result.IsFile) { string contentType = ContentType.GetContentType(file.Result.Name); return(PhysicalFile(physical_path, contentType, file.Result.Name)); } else { return(View()); // } }
public async Task CreateDocumentRelatedAsync(IFormFileCollection uploadedFile, ClaimsPrincipal owner, string parentId, string fdName = null) { string storagePath = Path.Combine(_pProvider.ContentPath()); string combinedFilePath = ""; string ownerId = _userRepo.GetUserId(owner); if (uploadedFile != null) { foreach (var file in uploadedFile) { if (_documentRepo.GetDocumentByIdAsync(parentId).Result.Length <= _userRepo.GetUserByIdAsync(ownerId).Result.StorageSize) { string docId = Guid.NewGuid().ToString(); foreach (var str in GetPathPartsBypId(parentId)) { combinedFilePath += str + "\\"; } combinedFilePath.Substring(combinedFilePath.Length - 2); var filePath = Path.Combine(storagePath, combinedFilePath, docId); var doc = new DocumentEntity { Name = file.FileName, Length = file.Length, IsFile = true, DocumentId = docId, OwnerId = ownerId, ParentId = parentId, Path = filePath, ChangeDate = DateTime.Now }; await _documentRepo.CreateDocumentAsync(doc); await _userDocumentRepo.AddUserDocumentAsync(ownerId, docId); await _pProvider.CreateFile(file, Path.Combine(storagePath, _userRepo.GetUserId(owner), docId)); await UpdateFolderLength(doc.ParentId); } } } else if (fdName != null) { string docId = Guid.NewGuid().ToString(); foreach (var str in GetPathPartsBypId(parentId)) { combinedFilePath += str + "\\"; } combinedFilePath.Substring(combinedFilePath.Length - 2); var filePath = Path.Combine(storagePath, combinedFilePath, docId); var doc = new DocumentEntity { Name = fdName, Length = 0, IsFile = false, DocumentId = docId, OwnerId = ownerId, ParentId = parentId, Path = filePath, ChangeDate = DateTime.Now }; await _documentRepo.CreateDocumentAsync(doc); await _userDocumentRepo.AddUserDocumentAsync(ownerId, docId); } }