public async Task <IActionResult> RenameFile(RenameFileAddressModel model) { var(sourceFolders, sourceFileName) = _folderSplitter.SplitToFoldersAndFile(model.FolderNames); var sourceFolder = await _folderRepo.GetFolderAsOwner(model.AccessToken, model.SiteName, sourceFolders); var file = sourceFolder.Files.SingleOrDefault(t => t.FileName == sourceFileName); if (file == null) { return(this.Protocol(ErrorType.NotFound, "The file cannot be found. Maybe it has been deleted.")); } var newFileName = _folderSplitter.GetValidFileName(existingFileNames: sourceFolder .Files .Where(t => t.Id != file.Id) .Select(t => t.FileName), expectedFileName: model.TargetFileName); await _fileRepo.UpdateName(file.Id, newFileName); var filePath = _probeLocator.GetProbeFullPath(model.SiteName, string.Join('/', sourceFileName), newFileName); var internetPath = _probeLocator.GetProbeOpenAddress(filePath); return(this.Protocol(new UploadFileViewModel { InternetPath = internetPath, SiteName = model.SiteName, FilePath = filePath, FileSize = file.FileSize, Code = ErrorType.Success, Message = "Successfully copied your file." })); }