Use string Interpolation for constructing Urls (#324)

This commit is contained in:
Hisham Bin Ateya 2020-04-03 19:44:54 +03:00 committed by GitHub
parent 2433cc06be
commit 7786cd027b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 124 additions and 108 deletions

View File

@ -36,7 +36,7 @@ namespace Oqtane.Services
public async Task<Alias> GetAliasAsync(int aliasId)
{
return await _http.GetJsonAsync<Alias>(Apiurl + "/" + aliasId.ToString());
return await _http.GetJsonAsync<Alias>($"{Apiurl}/{aliasId.ToString()}");
}
public async Task<Alias> GetAliasAsync(string url, DateTime lastSyncDate)
@ -51,7 +51,7 @@ namespace Oqtane.Services
{
name = name.Substring(0, name.Length - 1);
}
return await _http.GetJsonAsync<Alias>(Apiurl + "/name/" + WebUtility.UrlEncode(name) + "?lastsyncdate=" + lastSyncDate.ToString("yyyyMMddHHmmssfff"));
return await _http.GetJsonAsync<Alias>($"{Apiurl}/name/{WebUtility.UrlEncode(name)}?lastsyncdate={lastSyncDate.ToString("yyyyMMddHHmmssfff")}");
}
public async Task<Alias> AddAliasAsync(Alias alias)
@ -61,11 +61,11 @@ namespace Oqtane.Services
public async Task<Alias> UpdateAliasAsync(Alias alias)
{
return await _http.PutJsonAsync<Alias>(Apiurl + "/" + alias.AliasId.ToString(), alias);
return await _http.PutJsonAsync<Alias>($"{Apiurl}/{alias.AliasId.ToString()}", alias);
}
public async Task DeleteAliasAsync(int aliasId)
{
await _http.DeleteAsync(Apiurl + "/" + aliasId.ToString());
await _http.DeleteAsync($"{Apiurl}/{aliasId.ToString()}");
}
}
}

View File

@ -39,19 +39,24 @@ namespace Oqtane.Services
public async Task<List<File>> GetFilesAsync(string folder)
{
return await _http.GetJsonAsync<List<File>>(Apiurl + "?folder=" + folder);
return await _http.GetJsonAsync<List<File>>($"{Apiurl}?folder={folder}");
}
public async Task<List<File>> GetFilesAsync(int siteId, string folderPath)
{
if (!folderPath.EndsWith("\\")) folderPath += "\\";
if (!folderPath.EndsWith("\\"))
{
folderPath += "\\";
}
var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<List<File>>($"{Apiurl}/{siteId}/{path}");
}
public async Task<File> GetFileAsync(int fileId)
{
return await _http.GetJsonAsync<File>(Apiurl + "/" + fileId.ToString());
return await _http.GetJsonAsync<File>($"{Apiurl}/{fileId.ToString()}");
}
public async Task<File> AddFileAsync(File file)
@ -61,18 +66,17 @@ namespace Oqtane.Services
public async Task<File> UpdateFileAsync(File file)
{
return await _http.PutJsonAsync<File>(Apiurl + "/" + file.FileId.ToString(), file);
return await _http.PutJsonAsync<File>($"{Apiurl}/{file.FileId.ToString()}", file);
}
public async Task DeleteFileAsync(int fileId)
{
await _http.DeleteAsync(Apiurl + "/" + fileId.ToString());
await _http.DeleteAsync($"{Apiurl}/{fileId.ToString()}");
}
public async Task<File> UploadFileAsync(string url, int folderId)
{
return await _http.GetJsonAsync<File>(Apiurl + "/upload?url=" + WebUtility.UrlEncode(url) + "&folderid=" +
folderId.ToString());
return await _http.GetJsonAsync<File>($"{Apiurl}/upload?url={WebUtility.UrlEncode(url)}&folderid={folderId.ToString()}");
}
public async Task<string> UploadFilesAsync(int folderId, string[] files, string id)
@ -85,7 +89,7 @@ namespace Oqtane.Services
string result = "";
var interop = new Interop(_jsRuntime);
await interop.UploadFiles(Apiurl + "/upload", folder, id);
await interop.UploadFiles($"{Apiurl}/upload", folder, id);
// uploading files is asynchronous so we need to wait for the upload to complete
bool success = false;
@ -122,7 +126,7 @@ namespace Oqtane.Services
public async Task<byte[]> DownloadFileAsync(int fileId)
{
return await _http.GetByteArrayAsync(Apiurl + "/download/" + fileId.ToString());
return await _http.GetByteArrayAsync($"{Apiurl}/download/{fileId.ToString()}");
}
}
}

View File

@ -28,20 +28,25 @@ namespace Oqtane.Services
public async Task<List<Folder>> GetFoldersAsync(int siteId)
{
List<Folder> folders = await _http.GetJsonAsync<List<Folder>>(ApiUrl + "?siteid=" + siteId.ToString());
List<Folder> folders = await _http.GetJsonAsync<List<Folder>>($"{ApiUrl}?siteid={siteId.ToString()}");
folders = GetFoldersHierarchy(folders);
return folders;
}
public async Task<Folder> GetFolderAsync(int folderId)
{
return await _http.GetJsonAsync<Folder>(ApiUrl + "/" + folderId.ToString());
return await _http.GetJsonAsync<Folder>($"{ApiUrl}/{folderId.ToString()}");
}
public async Task<Folder> GetFolderAsync(int siteId, [NotNull] string folderPath)
{
if (!folderPath.EndsWith("\\")) folderPath += "\\";
if (!folderPath.EndsWith("\\"))
{
folderPath += "\\";
}
var path = WebUtility.UrlEncode(folderPath);
return await _http.GetJsonAsync<Folder>($"{ApiUrl}/{siteId}/{path}");
}
@ -52,19 +57,20 @@ namespace Oqtane.Services
public async Task<Folder> UpdateFolderAsync(Folder folder)
{
return await _http.PutJsonAsync<Folder>(ApiUrl + "/" + folder.FolderId.ToString(), folder);
return await _http.PutJsonAsync<Folder>($"{ApiUrl}/{folder.FolderId.ToString()}", folder);
}
public async Task UpdateFolderOrderAsync(int siteId, int folderId, int? parentId)
{
await _http.PutJsonAsync(
ApiUrl + "/?siteid=" + siteId.ToString() + "&folderid=" + folderId.ToString() + "&parentid=" +
((parentId == null) ? "" : parentId.ToString()), null);
var parent = parentId == null
? string.Empty
: parentId.ToString();
await _http.PutJsonAsync($"{ApiUrl}/?siteid={siteId.ToString()}&folderid={folderId.ToString()}&parentid={parent}", null);
}
public async Task DeleteFolderAsync(int folderId)
{
await _http.DeleteAsync(ApiUrl + "/" + folderId.ToString());
await _http.DeleteAsync($"{ApiUrl}/{folderId.ToString()}");
}
private static List<Folder> GetFoldersHierarchy(List<Folder> folders)

View File

@ -23,7 +23,7 @@ namespace Oqtane.Services
public async Task<Installation> IsInstalled()
{
return await _http.GetJsonAsync<Installation>(ApiUrl + "/installed");
return await _http.GetJsonAsync<Installation>($"{ApiUrl}/installed");
}
public async Task<Installation> Install(InstallConfig config)
@ -33,7 +33,7 @@ namespace Oqtane.Services
public async Task<Installation> Upgrade()
{
return await _http.GetJsonAsync<Installation>(ApiUrl + "/upgrade");
return await _http.GetJsonAsync<Installation>($"{ApiUrl}/upgrade");
}
}
}

View File

@ -34,7 +34,7 @@ namespace Oqtane.Services
public async Task<JobLog> GetJobLogAsync(int jobLogId)
{
return await _http.GetJsonAsync<JobLog>(Apiurl + "/" + jobLogId.ToString());
return await _http.GetJsonAsync<JobLog>($"{Apiurl}/{jobLogId.ToString()}");
}
public async Task<JobLog> AddJobLogAsync(JobLog joblog)
@ -44,11 +44,11 @@ namespace Oqtane.Services
public async Task<JobLog> UpdateJobLogAsync(JobLog joblog)
{
return await _http.PutJsonAsync<JobLog>(Apiurl + "/" + joblog.JobLogId.ToString(), joblog);
return await _http.PutJsonAsync<JobLog>($"{Apiurl}/{joblog.JobLogId.ToString()}", joblog);
}
public async Task DeleteJobLogAsync(int jobLogId)
{
await _http.DeleteAsync(Apiurl + "/" + jobLogId.ToString());
await _http.DeleteAsync($"{Apiurl}/{jobLogId.ToString()}");
}
}
}

View File

@ -34,7 +34,7 @@ namespace Oqtane.Services
public async Task<Job> GetJobAsync(int jobId)
{
return await _http.GetJsonAsync<Job>(Apiurl + "/" + jobId.ToString());
return await _http.GetJsonAsync<Job>($"{Apiurl}/{jobId.ToString()}");
}
public async Task<Job> AddJobAsync(Job job)
@ -44,21 +44,21 @@ namespace Oqtane.Services
public async Task<Job> UpdateJobAsync(Job job)
{
return await _http.PutJsonAsync<Job>(Apiurl + "/" + job.JobId.ToString(), job);
return await _http.PutJsonAsync<Job>($"{Apiurl}/{job.JobId.ToString()}", job);
}
public async Task DeleteJobAsync(int jobId)
{
await _http.DeleteAsync(Apiurl + "/" + jobId.ToString());
await _http.DeleteAsync($"{Apiurl}/{jobId.ToString()}");
}
public async Task StartJobAsync(int jobId)
{
await _http.GetAsync(Apiurl + "/start/" + jobId.ToString());
await _http.GetAsync($"{Apiurl}/start/{jobId.ToString()}");
}
public async Task StopJobAsync(int jobId)
{
await _http.GetAsync(Apiurl + "/stop/" + jobId.ToString());
await _http.GetAsync($"{Apiurl}/stop/{jobId.ToString()}");
}
}
}

View File

@ -30,12 +30,12 @@ namespace Oqtane.Services
public async Task<List<Log>> GetLogsAsync(int siteId, string level, string function, int rows)
{
return await _http.GetJsonAsync<List<Log>>(Apiurl + "?siteid=" + siteId.ToString() + "&level=" + level + "&function=" + function + "&rows=" + rows.ToString());
return await _http.GetJsonAsync<List<Log>>($"{Apiurl}?siteid={siteId.ToString()}&level={level}&function={function}&rows={rows.ToString()}");
}
public async Task<Log> GetLogAsync(int logId)
{
return await _http.GetJsonAsync<Log>(Apiurl + "/" + logId.ToString());
return await _http.GetJsonAsync<Log>($"{Apiurl}/{logId.ToString()}");
}
public async Task Log(int? pageId, int? moduleId, int? userId, string category, string feature, LogFunction function, LogLevel level, Exception exception, string message, params object[] args)

View File

@ -31,28 +31,28 @@ namespace Oqtane.Services
public async Task<List<ModuleDefinition>> GetModuleDefinitionsAsync(int siteId)
{
List<ModuleDefinition> moduledefinitions = await _http.GetJsonAsync<List<ModuleDefinition>>(Apiurl + "?siteid=" + siteId.ToString());
List<ModuleDefinition> moduledefinitions = await _http.GetJsonAsync<List<ModuleDefinition>>($"{Apiurl}?siteid={siteId.ToString()}");
return moduledefinitions.OrderBy(item => item.Name).ToList();
}
public async Task<ModuleDefinition> GetModuleDefinitionAsync(int moduleDefinitionId, int siteId)
{
return await _http.GetJsonAsync<ModuleDefinition>(Apiurl + "/" + moduleDefinitionId.ToString() + "?siteid=" + siteId.ToString());
return await _http.GetJsonAsync<ModuleDefinition>($"{Apiurl}/{moduleDefinitionId.ToString()}?siteid={siteId.ToString()}");
}
public async Task UpdateModuleDefinitionAsync(ModuleDefinition moduleDefinition)
{
await _http.PutJsonAsync(Apiurl + "/" + moduleDefinition.ModuleDefinitionId.ToString(), moduleDefinition);
await _http.PutJsonAsync($"{Apiurl}/{moduleDefinition.ModuleDefinitionId.ToString()}", moduleDefinition);
}
public async Task InstallModuleDefinitionsAsync()
{
await _http.GetJsonAsync<List<string>>(Apiurl + "/install");
await _http.GetJsonAsync<List<string>>($"{Apiurl}/install");
}
public async Task DeleteModuleDefinitionAsync(int moduleDefinitionId, int siteId)
{
await _http.DeleteAsync(Apiurl + "/" + moduleDefinitionId.ToString() + "?siteid=" + siteId.ToString());
await _http.DeleteAsync($"{Apiurl}/{moduleDefinitionId.ToString()}?siteid={siteId.ToString()}");
}
public async Task LoadModuleDefinitionsAsync(int siteId, Runtime runtime)
@ -77,7 +77,7 @@ namespace Oqtane.Services
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(Apiurl + "/load/" + assemblyname + ".dll");
var bytes = await _http.GetByteArrayAsync($"{Apiurl}/load/{assemblyname}.dll");
Assembly.Load(bytes);
}
}
@ -86,7 +86,7 @@ namespace Oqtane.Services
if (assemblies.Where(item => item.FullName.StartsWith(moduledefinition.AssemblyName + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(Apiurl + "/load/" + moduledefinition.AssemblyName + ".dll");
var bytes = await _http.GetByteArrayAsync($"{Apiurl}/load/{moduledefinition.AssemblyName}.dll");
Assembly.Load(bytes);
}
}
@ -94,7 +94,7 @@ namespace Oqtane.Services
}
public async Task CreateModuleDefinitionAsync(ModuleDefinition moduleDefinition, int moduleId)
{
await _http.PostJsonAsync(Apiurl + "?moduleid=" + moduleId.ToString(), moduleDefinition);
await _http.PostJsonAsync($"{Apiurl}?moduleid={moduleId.ToString()}", moduleDefinition);
}
}
}

View File

@ -28,7 +28,7 @@ namespace Oqtane.Services
public async Task<List<Module>> GetModulesAsync(int siteId)
{
List<Module> modules = await _http.GetJsonAsync<List<Module>>(Apiurl + "?siteid=" + siteId.ToString());
List<Module> modules = await _http.GetJsonAsync<List<Module>>($"{Apiurl}?siteid={siteId.ToString()}");
modules = modules
.OrderBy(item => item.Order)
.ToList();
@ -37,7 +37,7 @@ namespace Oqtane.Services
public async Task<Module> GetModuleAsync(int moduleId)
{
return await _http.GetJsonAsync<Module>(Apiurl + "/" + moduleId.ToString());
return await _http.GetJsonAsync<Module>($"{Apiurl}/{moduleId.ToString()}");
}
public async Task<Module> AddModuleAsync(Module module)
@ -47,22 +47,22 @@ namespace Oqtane.Services
public async Task<Module> UpdateModuleAsync(Module module)
{
return await _http.PutJsonAsync<Module>(Apiurl + "/" + module.ModuleId.ToString(), module);
return await _http.PutJsonAsync<Module>($"{Apiurl}/{module.ModuleId.ToString()}", module);
}
public async Task DeleteModuleAsync(int moduleId)
{
await _http.DeleteAsync(Apiurl + "/" + moduleId.ToString());
await _http.DeleteAsync($"{Apiurl}/{moduleId.ToString()}");
}
public async Task<bool> ImportModuleAsync(int moduleId, string content)
{
return await _http.PostJsonAsync<bool>(Apiurl + "/import?moduleid=" + moduleId, content);
return await _http.PostJsonAsync<bool>($"{Apiurl}/import?moduleid={moduleId}", content);
}
public async Task<string> ExportModuleAsync(int moduleId)
{
return await _http.GetStringAsync(Apiurl + "/export?moduleid=" + moduleId.ToString());
return await _http.GetStringAsync($"{Apiurl}/export?moduleid={moduleId.ToString()}");
}
}
}

View File

@ -28,14 +28,14 @@ namespace Oqtane.Services
public async Task<List<Notification>> GetNotificationsAsync(int siteId, string direction, int userId)
{
string querystring = "?siteid=" + siteId.ToString() + "&direction=" + direction.ToLower() + "&userid=" + userId.ToString();
List<Notification> notifications = await _http.GetJsonAsync<List<Notification>>(Apiurl + querystring);
var notifications = await _http.GetJsonAsync<List<Notification>>($"{Apiurl}? siteid={siteId.ToString()}&direction={direction.ToLower()}&userid={userId.ToString()}");
return notifications.OrderByDescending(item => item.CreatedOn).ToList();
}
public async Task<Notification> GetNotificationAsync(int notificationId)
{
return await _http.GetJsonAsync<Notification>(Apiurl + "/" + notificationId.ToString());
return await _http.GetJsonAsync<Notification>($"{Apiurl}/{notificationId.ToString()}");
}
public async Task<Notification> AddNotificationAsync(Notification notification)
@ -45,11 +45,11 @@ namespace Oqtane.Services
public async Task<Notification> UpdateNotificationAsync(Notification notification)
{
return await _http.PutJsonAsync<Notification>(Apiurl + "/" + notification.NotificationId.ToString(), notification);
return await _http.PutJsonAsync<Notification>($"{Apiurl}/{notification.NotificationId.ToString()}", notification);
}
public async Task DeleteNotificationAsync(int notificationId)
{
await _http.DeleteAsync(Apiurl + "/" + notificationId.ToString());
await _http.DeleteAsync($"{Apiurl}/{notificationId.ToString()}");
}
}
}

View File

@ -28,13 +28,13 @@ namespace Oqtane.Services
public async Task<List<Package>> GetPackagesAsync(string tag)
{
List<Package> packages = await _http.GetJsonAsync<List<Package>>(Apiurl + "?tag=" + tag);
List<Package> packages = await _http.GetJsonAsync<List<Package>>($"{Apiurl}?tag={tag}");
return packages.OrderByDescending(item => item.Downloads).ToList();
}
public async Task DownloadPackageAsync(string packageId, string version, string folder)
{
await _http.PostJsonAsync(Apiurl + "?packageid=" + packageId + "&version=" + version + "&folder=" + folder, null);
await _http.PostJsonAsync($"{Apiurl}?packageid={packageId}&version={version}&folder={folder}", null);
}
}
}

View File

@ -26,12 +26,12 @@ namespace Oqtane.Services
public async Task<PageModule> GetPageModuleAsync(int pageModuleId)
{
return await _http.GetJsonAsync<PageModule>(Apiurl + "/" + pageModuleId.ToString());
return await _http.GetJsonAsync<PageModule>($"{Apiurl}/{pageModuleId.ToString()}");
}
public async Task<PageModule> GetPageModuleAsync(int pageId, int moduleId)
{
return await _http.GetJsonAsync<PageModule>(Apiurl + "/" + pageId.ToString() + "/" + moduleId.ToString());
return await _http.GetJsonAsync<PageModule>($"{Apiurl}/{pageId.ToString()}/{moduleId.ToString()}");
}
public async Task<PageModule> AddPageModuleAsync(PageModule pageModule)
@ -41,17 +41,17 @@ namespace Oqtane.Services
public async Task<PageModule> UpdatePageModuleAsync(PageModule pageModule)
{
return await _http.PutJsonAsync<PageModule>(Apiurl + "/" + pageModule.PageModuleId.ToString(), pageModule);
return await _http.PutJsonAsync<PageModule>($"{Apiurl}/{pageModule.PageModuleId.ToString()}", pageModule);
}
public async Task UpdatePageModuleOrderAsync(int pageId, string pane)
{
await _http.PutJsonAsync(Apiurl + "/?pageid=" + pageId.ToString() + "&pane=" + pane, null);
await _http.PutJsonAsync($"{Apiurl}/?pageid={pageId.ToString()}&pane={pane}", null);
}
public async Task DeletePageModuleAsync(int pageModuleId)
{
await _http.DeleteAsync(Apiurl + "/" + pageModuleId.ToString());
await _http.DeleteAsync($"{Apiurl}/{pageModuleId.ToString()}");
}
}
}

View File

@ -30,26 +30,26 @@ namespace Oqtane.Services
public async Task<List<Page>> GetPagesAsync(int siteId)
{
List<Page> pages = await _http.GetJsonAsync<List<Page>>(Apiurl + "?siteid=" + siteId.ToString());
List<Page> pages = await _http.GetJsonAsync<List<Page>>($"{Apiurl}?siteid={siteId.ToString()}");
pages = GetPagesHierarchy(pages);
return pages;
}
public async Task<Page> GetPageAsync(int pageId)
{
return await _http.GetJsonAsync<Page>(Apiurl + "/" + pageId.ToString());
return await _http.GetJsonAsync<Page>($"{Apiurl}/{pageId.ToString()}");
}
public async Task<Page> GetPageAsync(int pageId, int userId)
{
return await _http.GetJsonAsync<Page>(Apiurl + "/" + pageId.ToString() + "?userid=" + userId.ToString());
return await _http.GetJsonAsync<Page>($"{Apiurl}/{pageId.ToString()}?userid={userId.ToString()}");
}
public async Task<Page> GetPageAsync(string path, int siteId)
{
try
{
return await _http.GetJsonAsync<Page>(Apiurl + "/path/" + siteId.ToString() + "?path=" + WebUtility.UrlEncode(path));
return await _http.GetJsonAsync<Page>($"{Apiurl}/path/{siteId.ToString()}?path={WebUtility.UrlEncode(path)}");
}
catch
{
@ -64,22 +64,25 @@ namespace Oqtane.Services
public async Task<Page> AddPageAsync(int pageId, int userId)
{
return await _http.PostJsonAsync<Page>(Apiurl + "/" + pageId.ToString() + "?userid=" + userId.ToString(), null);
return await _http.PostJsonAsync<Page>($"{Apiurl}/{pageId.ToString()}?userid={userId.ToString()}", null);
}
public async Task<Page> UpdatePageAsync(Page page)
{
return await _http.PutJsonAsync<Page>(Apiurl + "/" + page.PageId.ToString(), page);
return await _http.PutJsonAsync<Page>($"{Apiurl}/{page.PageId.ToString()}", page);
}
public async Task UpdatePageOrderAsync(int siteId, int pageId, int? parentId)
{
await _http.PutJsonAsync(Apiurl + "/?siteid=" + siteId.ToString() + "&pageid=" + pageId.ToString() + "&parentid=" + ((parentId == null) ? "" : parentId.ToString()), null);
var parent = parentId == null
? string.Empty
: parentId.ToString();
await _http.PutJsonAsync($"{Apiurl}/?siteid={siteId.ToString()}&pageid={pageId.ToString()}&parentid={parent}", null);
}
public async Task DeletePageAsync(int pageId)
{
await _http.DeleteAsync(Apiurl + "/" + pageId.ToString());
await _http.DeleteAsync($"{Apiurl}/{pageId.ToString()}");
}
private static List<Page> GetPagesHierarchy(List<Page> pages)

View File

@ -28,13 +28,13 @@ namespace Oqtane.Services
public async Task<List<Profile>> GetProfilesAsync(int siteId)
{
List<Profile> profiles = await _http.GetJsonAsync<List<Profile>>(Apiurl + "?siteid=" + siteId.ToString());
List<Profile> profiles = await _http.GetJsonAsync<List<Profile>>($"{Apiurl}?siteid={siteId.ToString()}");
return profiles.OrderBy(item => item.ViewOrder).ToList();
}
public async Task<Profile> GetProfileAsync(int profileId)
{
return await _http.GetJsonAsync<Profile>(Apiurl + "/" + profileId.ToString());
return await _http.GetJsonAsync<Profile>($"{Apiurl}/{profileId.ToString()}");
}
public async Task<Profile> AddProfileAsync(Profile profile)
@ -44,11 +44,11 @@ namespace Oqtane.Services
public async Task<Profile> UpdateProfileAsync(Profile profile)
{
return await _http.PutJsonAsync<Profile>(Apiurl + "/" + profile.SiteId.ToString(), profile);
return await _http.PutJsonAsync<Profile>($"{Apiurl}/{profile.SiteId.ToString()}", profile);
}
public async Task DeleteProfileAsync(int profileId)
{
await _http.DeleteAsync(Apiurl + "/" + profileId.ToString());
await _http.DeleteAsync($"{Apiurl}/{profileId.ToString()}");
}
}
}

View File

@ -28,13 +28,13 @@ namespace Oqtane.Services
public async Task<List<Role>> GetRolesAsync(int siteId)
{
List<Role> roles = await _http.GetJsonAsync<List<Role>>(Apiurl + "?siteid=" + siteId.ToString());
List<Role> roles = await _http.GetJsonAsync<List<Role>>($"{Apiurl}?siteid={siteId.ToString()}");
return roles.OrderBy(item => item.Name).ToList();
}
public async Task<Role> GetRoleAsync(int roleId)
{
return await _http.GetJsonAsync<Role>(Apiurl + "/" + roleId.ToString());
return await _http.GetJsonAsync<Role>($"{Apiurl}/{roleId.ToString()}");
}
public async Task<Role> AddRoleAsync(Role role)
@ -44,11 +44,11 @@ namespace Oqtane.Services
public async Task<Role> UpdateRoleAsync(Role role)
{
return await _http.PutJsonAsync<Role>(Apiurl + "/" + role.RoleId.ToString(), role);
return await _http.PutJsonAsync<Role>($"{Apiurl}/{role.RoleId.ToString()}", role);
}
public async Task DeleteRoleAsync(int roleId)
{
await _http.DeleteAsync(Apiurl + "/" + roleId.ToString());
await _http.DeleteAsync($"{Apiurl}/{roleId.ToString()}");
}
}
}

View File

@ -14,8 +14,8 @@ namespace Oqtane.Services
if (alias != null)
{
// build a url which passes the alias that may include a subfolder for multi-tenancy
apiurl = uri.Scheme + "://" + alias.Name + "/";
if (alias.Path == "")
apiurl = $"{uri.Scheme}://{alias.Name}/";
if (alias.Path == string.Empty)
{
apiurl += "~/";
}
@ -23,9 +23,10 @@ namespace Oqtane.Services
else
{
// build a url which ignores any subfolder for multi-tenancy
apiurl = uri.Scheme + "://" + uri.Authority + "/~/";
apiurl = $"{uri.Scheme}://{uri.Authority}/~/";
}
apiurl += "api/" + serviceName;
apiurl += $"api/{serviceName}";
return apiurl;
}

View File

@ -98,8 +98,9 @@ namespace Oqtane.Services
public async Task<Dictionary<string, string>> GetSettingsAsync(string entityName, int entityId)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
List<Setting> settings = await _http.GetJsonAsync<List<Setting>>(Apiurl + "?entityname=" + entityName + "&entityid=" + entityId.ToString());
var dictionary = new Dictionary<string, string>();
var settings = await _http.GetJsonAsync<List<Setting>>($"{Apiurl}?entityname={entityName}&entityid={entityId.ToString()}");
foreach(Setting setting in settings.OrderBy(item => item.SettingName).ToList())
{
dictionary.Add(setting.SettingName, setting.SettingValue);
@ -109,7 +110,8 @@ namespace Oqtane.Services
public async Task UpdateSettingsAsync(Dictionary<string, string> settings, string entityName, int entityId)
{
List<Setting> settingsList = await _http.GetJsonAsync<List<Setting>>(Apiurl + "?entityname=" + entityName + "&entityid=" + entityId.ToString());
var settingsList = await _http.GetJsonAsync<List<Setting>>($"{Apiurl}?entityname={entityName}&entityid={entityId.ToString()}");
foreach (KeyValuePair<string, string> kvp in settings)
{
Setting setting = settingsList.FirstOrDefault(item => item.SettingName == kvp.Key);
@ -136,7 +138,7 @@ namespace Oqtane.Services
public async Task<Setting> GetSettingAsync(int settingId)
{
return await _http.GetJsonAsync<Setting>(Apiurl + "/" + settingId.ToString());
return await _http.GetJsonAsync<Setting>($"{Apiurl}/{settingId.ToString()}");
}
public async Task<Setting> AddSettingAsync(Setting setting)
@ -146,12 +148,12 @@ namespace Oqtane.Services
public async Task<Setting> UpdateSettingAsync(Setting setting)
{
return await _http.PutJsonAsync<Setting>(Apiurl + "/" + setting.SettingId.ToString(), setting);
return await _http.PutJsonAsync<Setting>($"{Apiurl}/{setting.SettingId.ToString()}", setting);
}
public async Task DeleteSettingAsync(int settingId)
{
await _http.DeleteAsync(Apiurl + "/" + settingId.ToString());
await _http.DeleteAsync($"{Apiurl}/{settingId.ToString()}");
}

View File

@ -34,7 +34,7 @@ namespace Oqtane.Services
public async Task<Site> GetSiteAsync(int siteId, Alias alias)
{
return await _http.GetJsonAsync<Site>(CreateCrossTenantUrl(Apiurl + "/" + siteId.ToString(), alias));
return await _http.GetJsonAsync<Site>(CreateCrossTenantUrl($"{Apiurl}/{siteId.ToString()}", alias));
}
public async Task<Site> AddSiteAsync(Site site, Alias alias)
@ -44,12 +44,12 @@ namespace Oqtane.Services
public async Task<Site> UpdateSiteAsync(Site site, Alias alias)
{
return await _http.PutJsonAsync<Site>(CreateCrossTenantUrl(Apiurl + "/" + site.SiteId.ToString(), alias), site);
return await _http.PutJsonAsync<Site>(CreateCrossTenantUrl($"{Apiurl}/{site.SiteId.ToString()}", alias), site);
}
public async Task DeleteSiteAsync(int siteId, Alias alias)
{
await _http.DeleteAsync(CreateCrossTenantUrl(Apiurl + "/" + siteId.ToString(), alias));
await _http.DeleteAsync(CreateCrossTenantUrl($"{Apiurl}/{siteId.ToString()}", alias));
}
}
}

View File

@ -34,7 +34,7 @@ namespace Oqtane.Services
public async Task<Tenant> GetTenantAsync(int tenantId)
{
return await _http.GetJsonAsync<Tenant>(Apiurl + "/" + tenantId.ToString());
return await _http.GetJsonAsync<Tenant>($"{Apiurl}/{tenantId.ToString()}");
}
public async Task<Tenant> AddTenantAsync(Tenant tenant)
@ -44,12 +44,12 @@ namespace Oqtane.Services
public async Task<Tenant> UpdateTenantAsync(Tenant tenant)
{
return await _http.PutJsonAsync<Tenant>(Apiurl + "/" + tenant.TenantId.ToString(), tenant);
return await _http.PutJsonAsync<Tenant>($"{Apiurl}/{tenant.TenantId.ToString()}", tenant);
}
public async Task DeleteTenantAsync(int tenantId)
{
await _http.DeleteAsync(Apiurl + "/" + tenantId.ToString());
await _http.DeleteAsync($"{Apiurl}/{tenantId.ToString()}");
}
}
}

View File

@ -45,7 +45,7 @@ namespace Oqtane.Services
if (assemblies.Where(item => item.FullName.StartsWith(assemblyname + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(Apiurl + "/load/" + assemblyname + ".dll");
var bytes = await _http.GetByteArrayAsync($"{Apiurl}/load/{assemblyname}.dll");
Assembly.Load(bytes);
}
}
@ -53,7 +53,7 @@ namespace Oqtane.Services
if (assemblies.Where(item => item.FullName.StartsWith(theme.AssemblyName + ",")).FirstOrDefault() == null)
{
// download assembly from server and load
var bytes = await _http.GetByteArrayAsync(Apiurl + "/load/" + theme.AssemblyName + ".dll");
var bytes = await _http.GetByteArrayAsync($"{Apiurl}/load/{theme.AssemblyName}.dll");
Assembly.Load(bytes);
}
}
@ -105,12 +105,12 @@ namespace Oqtane.Services
public async Task InstallThemesAsync()
{
await _http.GetJsonAsync<List<string>>(Apiurl + "/install");
await _http.GetJsonAsync<List<string>>($"{Apiurl}/install");
}
public async Task DeleteThemeAsync(string themeName)
{
await _http.DeleteAsync(Apiurl + "/" + themeName);
await _http.DeleteAsync($"{Apiurl}/{themeName}");
}
}
}

View File

@ -27,12 +27,12 @@ namespace Oqtane.Services
public async Task<List<UserRole>> GetUserRolesAsync(int siteId)
{
return await _http.GetJsonAsync<List<UserRole>>(Apiurl + "?siteid=" + siteId.ToString());
return await _http.GetJsonAsync<List<UserRole>>($"{Apiurl}?siteid={siteId.ToString()}");
}
public async Task<UserRole> GetUserRoleAsync(int userRoleId)
{
return await _http.GetJsonAsync<UserRole>(Apiurl + "/" + userRoleId.ToString());
return await _http.GetJsonAsync<UserRole>($"{Apiurl}/{userRoleId.ToString()}");
}
public async Task<UserRole> AddUserRoleAsync(UserRole userRole)
@ -42,12 +42,12 @@ namespace Oqtane.Services
public async Task<UserRole> UpdateUserRoleAsync(UserRole userRole)
{
return await _http.PutJsonAsync<UserRole>(Apiurl + "/" + userRole.UserRoleId.ToString(), userRole);
return await _http.PutJsonAsync<UserRole>($"{Apiurl}/{userRole.UserRoleId.ToString()}", userRole);
}
public async Task DeleteUserRoleAsync(int userRoleId)
{
await _http.DeleteAsync(Apiurl + "/" + userRoleId.ToString());
await _http.DeleteAsync($"{Apiurl}/{userRoleId.ToString()}");
}
}
}

View File

@ -26,12 +26,12 @@ namespace Oqtane.Services
public async Task<User> GetUserAsync(int userId, int siteId)
{
return await _http.GetJsonAsync<User>(Apiurl + "/" + userId.ToString() + "?siteid=" + siteId.ToString());
return await _http.GetJsonAsync<User>($"{Apiurl}/{userId.ToString()}?siteid={siteId.ToString()}");
}
public async Task<User> GetUserAsync(string username, int siteId)
{
return await _http.GetJsonAsync<User>(Apiurl + "/name/" + username + "?siteid=" + siteId.ToString());
return await _http.GetJsonAsync<User>($"{Apiurl}/name/{username}?siteid={siteId.ToString()}");
}
public async Task<User> AddUserAsync(User user)
@ -60,37 +60,37 @@ namespace Oqtane.Services
public async Task<User> UpdateUserAsync(User user)
{
return await _http.PutJsonAsync<User>(Apiurl + "/" + user.UserId.ToString(), user);
return await _http.PutJsonAsync<User>($"{Apiurl}/{user.UserId.ToString()}", user);
}
public async Task DeleteUserAsync(int userId)
{
await _http.DeleteAsync(Apiurl + "/" + userId.ToString());
await _http.DeleteAsync($"{Apiurl}/{userId.ToString()}");
}
public async Task<User> LoginUserAsync(User user, bool setCookie, bool isPersistent)
{
return await _http.PostJsonAsync<User>(Apiurl + "/login?setcookie=" + setCookie.ToString() + "&persistent=" + isPersistent.ToString(), user);
return await _http.PostJsonAsync<User>($"{Apiurl}/login?setcookie={setCookie.ToString()}&persistent={isPersistent.ToString()}", user);
}
public async Task LogoutUserAsync(User user)
{
// best practices recommend post is preferrable to get for logout
await _http.PostJsonAsync(Apiurl + "/logout", user);
await _http.PostJsonAsync($"{Apiurl}/logout", user);
}
public async Task<User> VerifyEmailAsync(User user, string token)
{
return await _http.PostJsonAsync<User>(Apiurl + "/verify?token=" + token, user);
return await _http.PostJsonAsync<User>($"{Apiurl}/verify?token={token}", user);
}
public async Task ForgotPasswordAsync(User user)
{
await _http.PostJsonAsync(Apiurl + "/forgot", user);
await _http.PostJsonAsync($"{Apiurl}/forgot", user);
}
public async Task<User> ResetPasswordAsync(User user, string token)
{
return await _http.PostJsonAsync<User>(Apiurl + "/reset?token=" + token, user);
return await _http.PostJsonAsync<User>($"{Apiurl}/reset?token={token}", user);
}
}