public ActionResult InfoStorage(string id) { myFileMetadata md = FileVerification(id, StoragePath, true); if (md.FileInfo is null) { _logger.LogError("Не удалось получить информацию по файлу: {0}", Path.Combine(UploadsPath, id)); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Ошибка обработки запроса", Status = StylesMessageEnum.warning.ToString() })); } id = id.Substring(0, id.Length - md.FileInfo.Extension.Length); int idObject = int.Parse(id); FileStorageObjectModel fileStorage = DbContext.FilesStorage.Find(idObject); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Доступ к начальной папке успешно обработан", Status = StylesMessageEnum.success.ToString(), Tag = new { Id = fileStorage.Id.ToString() + md.FileInfo.Extension, fileStorage.Name, Size = glob_tools.SizeDataAsString(fileStorage.Length), fileStorage.isDisabled, fileStorage.isReadonly } })); }
public FileStorageObjectModel UploadFile(string sourceFilePath, string shortFileNameWithExtension, bool isMoveFile = true) { FileInfo fileInfo = new FileInfo(sourceFilePath); if (!fileInfo.Exists) { return(null); } FileStorageObjectModel newStorageFile = new FileStorageObjectModel() { Name = shortFileNameWithExtension, Information = shortFileNameWithExtension, Length = fileInfo.Length }; DbContext.FilesStorage.Add(newStorageFile); DbContext.SaveChanges(); try { if (isMoveFile) { fileInfo.MoveTo(Path.Combine(StoragePath, newStorageFile.Id.ToString() + fileInfo.Extension)); } else { fileInfo.CopyTo(Path.Combine(StoragePath, newStorageFile.Id.ToString() + fileInfo.Extension)); } return(newStorageFile); } catch (IOException ex) { _logger.LogError("Ошибка доступа к диску: {0}", ex.Message); DbContext.FilesStorage.Remove(newStorageFile); DbContext.SaveChanges(); return(null); } }
public ActionResult MoveFileToStorage(string id) { myFileMetadata md = FileVerification(id, UploadsPath); if (md.FileInfo is null) { _logger.LogError("Не удалось получить информацию по файлу: {0}", Path.Combine(UploadsPath, id)); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Ошибка обработки запроса", Status = StylesMessageEnum.warning.ToString() })); } FileStorageObjectModel storedFile = UploadFile(md.FileInfo.FullName, md.FileInfo.Name); if (storedFile is null) { _logger.LogError("Не удалось получить информацию по файлу: {0}", md.FileInfo.FullName); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Ошибка обработки запроса", Status = StylesMessageEnum.warning.ToString() })); } return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Файл сохранён", Status = StylesMessageEnum.success.ToString(), Tag = new { storedFile, storedFile.Name, Size = glob_tools.SizeDataAsString(storedFile.Length) } })); }