Merge pull request #1047 from chlupac/GetPath

Introduce GetFolderPath and GetFilePath repository methods
This commit is contained in:
Shaun Walker
2021-01-12 09:41:09 -05:00
committed by GitHub
5 changed files with 48 additions and 14 deletions

View File

@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Oqtane.Extensions;
using Oqtane.Models;
using Oqtane.Shared;
using File = Oqtane.Models.File;
namespace Oqtane.Repository
{
@ -11,11 +13,13 @@ namespace Oqtane.Repository
{
private TenantDBContext _db;
private readonly IPermissionRepository _permissions;
private readonly IFolderRepository _folderRepository;
public FileRepository(TenantDBContext context, IPermissionRepository permissions)
public FileRepository(TenantDBContext context, IPermissionRepository permissions, IFolderRepository folderRepository)
{
_db = context;
_permissions = permissions;
_folderRepository = folderRepository;
}
public IEnumerable<File> GetFiles(int folderId)
@ -74,5 +78,19 @@ namespace Oqtane.Repository
_db.File.Remove(file);
_db.SaveChanges();
}
public string GetFilePath(int fileId)
{
var file = _db.File.Find(fileId);
return GetFilePath(file);
}
public string GetFilePath(File file)
{
if (file == null) return null;
var folder = file.Folder ?? _db.Folder.Find(file.FolderId);
var filepath = Path.Combine(_folderRepository.GetFolderPath(folder), file.Name);
return filepath;
}
}
}

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Oqtane.Extensions;
using Oqtane.Models;
@ -11,11 +12,15 @@ namespace Oqtane.Repository
{
private TenantDBContext _db;
private readonly IPermissionRepository _permissions;
private readonly IWebHostEnvironment _environment;
private readonly ITenantResolver _tenants;
public FolderRepository(TenantDBContext context, IPermissionRepository permissions)
public FolderRepository(TenantDBContext context, IPermissionRepository permissions,IWebHostEnvironment environment, ITenantResolver tenants)
{
_db = context;
_permissions = permissions;
_environment = environment;
_tenants = tenants;
}
public IEnumerable<Folder> GetFolders(int siteId)
@ -85,5 +90,17 @@ namespace Oqtane.Repository
_db.Folder.Remove(folder);
_db.SaveChanges();
}
public string GetFolderPath(int folderId)
{
Folder folder = _db.Folder.Find(folderId);
return GetFolderPath(folder);
}
public string GetFolderPath(Folder folder)
{
return Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path);
}
}
}

View File

@ -11,5 +11,7 @@ namespace Oqtane.Repository
File GetFile(int fileId);
File GetFile(int fileId, bool tracking);
void DeleteFile(int fileId);
string GetFilePath(int fileId);
string GetFilePath(File file);
}
}

View File

@ -12,5 +12,7 @@ namespace Oqtane.Repository
Folder GetFolder(int folderId, bool tracking);
Folder GetFolder(int siteId, string path);
void DeleteFolder(int folderId);
string GetFolderPath(int folderId);
string GetFolderPath(Folder folder);
}
}