diff --git a/Oqtane.Client/Services/AliasService.cs b/Oqtane.Client/Services/AliasService.cs index 82b26061..d7fdf3e6 100644 --- a/Oqtane.Client/Services/AliasService.cs +++ b/Oqtane.Client/Services/AliasService.cs @@ -36,7 +36,7 @@ namespace Oqtane.Services public async Task GetAliasAsync(int aliasId) { - return await _http.GetJsonAsync(Apiurl + "/" + aliasId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{aliasId.ToString()}"); } public async Task GetAliasAsync(string url, DateTime lastSyncDate) @@ -51,7 +51,7 @@ namespace Oqtane.Services { name = name.Substring(0, name.Length - 1); } - return await _http.GetJsonAsync(Apiurl + "/name/" + WebUtility.UrlEncode(name) + "?lastsyncdate=" + lastSyncDate.ToString("yyyyMMddHHmmssfff")); + return await _http.GetJsonAsync($"{Apiurl}/name/{WebUtility.UrlEncode(name)}?lastsyncdate={lastSyncDate.ToString("yyyyMMddHHmmssfff")}"); } public async Task AddAliasAsync(Alias alias) @@ -61,11 +61,11 @@ namespace Oqtane.Services public async Task UpdateAliasAsync(Alias alias) { - return await _http.PutJsonAsync(Apiurl + "/" + alias.AliasId.ToString(), alias); + return await _http.PutJsonAsync($"{Apiurl}/{alias.AliasId.ToString()}", alias); } public async Task DeleteAliasAsync(int aliasId) { - await _http.DeleteAsync(Apiurl + "/" + aliasId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{aliasId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/FileService.cs b/Oqtane.Client/Services/FileService.cs index d3f419ee..3a875ac4 100644 --- a/Oqtane.Client/Services/FileService.cs +++ b/Oqtane.Client/Services/FileService.cs @@ -39,19 +39,24 @@ namespace Oqtane.Services public async Task> GetFilesAsync(string folder) { - return await _http.GetJsonAsync>(Apiurl + "?folder=" + folder); + return await _http.GetJsonAsync>($"{Apiurl}?folder={folder}"); } public async Task> GetFilesAsync(int siteId, string folderPath) { - if (!folderPath.EndsWith("\\")) folderPath += "\\"; + if (!folderPath.EndsWith("\\")) + { + folderPath += "\\"; + } + var path = WebUtility.UrlEncode(folderPath); + return await _http.GetJsonAsync>($"{Apiurl}/{siteId}/{path}"); } public async Task GetFileAsync(int fileId) { - return await _http.GetJsonAsync(Apiurl + "/" + fileId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{fileId.ToString()}"); } public async Task AddFileAsync(File file) @@ -61,18 +66,17 @@ namespace Oqtane.Services public async Task UpdateFileAsync(File file) { - return await _http.PutJsonAsync(Apiurl + "/" + file.FileId.ToString(), file); + return await _http.PutJsonAsync($"{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 UploadFileAsync(string url, int folderId) { - return await _http.GetJsonAsync(Apiurl + "/upload?url=" + WebUtility.UrlEncode(url) + "&folderid=" + - folderId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/upload?url={WebUtility.UrlEncode(url)}&folderid={folderId.ToString()}"); } public async Task 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 DownloadFileAsync(int fileId) { - return await _http.GetByteArrayAsync(Apiurl + "/download/" + fileId.ToString()); + return await _http.GetByteArrayAsync($"{Apiurl}/download/{fileId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/FolderService.cs b/Oqtane.Client/Services/FolderService.cs index 3c80957c..642aeafa 100644 --- a/Oqtane.Client/Services/FolderService.cs +++ b/Oqtane.Client/Services/FolderService.cs @@ -28,20 +28,25 @@ namespace Oqtane.Services public async Task> GetFoldersAsync(int siteId) { - List folders = await _http.GetJsonAsync>(ApiUrl + "?siteid=" + siteId.ToString()); + List folders = await _http.GetJsonAsync>($"{ApiUrl}?siteid={siteId.ToString()}"); folders = GetFoldersHierarchy(folders); return folders; } public async Task GetFolderAsync(int folderId) { - return await _http.GetJsonAsync(ApiUrl + "/" + folderId.ToString()); + return await _http.GetJsonAsync($"{ApiUrl}/{folderId.ToString()}"); } public async Task GetFolderAsync(int siteId, [NotNull] string folderPath) { - if (!folderPath.EndsWith("\\")) folderPath += "\\"; + if (!folderPath.EndsWith("\\")) + { + folderPath += "\\"; + } + var path = WebUtility.UrlEncode(folderPath); + return await _http.GetJsonAsync($"{ApiUrl}/{siteId}/{path}"); } @@ -52,19 +57,20 @@ namespace Oqtane.Services public async Task UpdateFolderAsync(Folder folder) { - return await _http.PutJsonAsync(ApiUrl + "/" + folder.FolderId.ToString(), folder); + return await _http.PutJsonAsync($"{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 GetFoldersHierarchy(List folders) diff --git a/Oqtane.Client/Services/InstallationService.cs b/Oqtane.Client/Services/InstallationService.cs index 0a11650b..40da3010 100644 --- a/Oqtane.Client/Services/InstallationService.cs +++ b/Oqtane.Client/Services/InstallationService.cs @@ -23,7 +23,7 @@ namespace Oqtane.Services public async Task IsInstalled() { - return await _http.GetJsonAsync(ApiUrl + "/installed"); + return await _http.GetJsonAsync($"{ApiUrl}/installed"); } public async Task Install(InstallConfig config) @@ -33,7 +33,7 @@ namespace Oqtane.Services public async Task Upgrade() { - return await _http.GetJsonAsync(ApiUrl + "/upgrade"); + return await _http.GetJsonAsync($"{ApiUrl}/upgrade"); } } } diff --git a/Oqtane.Client/Services/JobLogService.cs b/Oqtane.Client/Services/JobLogService.cs index e1bd8bfa..f564f46c 100644 --- a/Oqtane.Client/Services/JobLogService.cs +++ b/Oqtane.Client/Services/JobLogService.cs @@ -34,7 +34,7 @@ namespace Oqtane.Services public async Task GetJobLogAsync(int jobLogId) { - return await _http.GetJsonAsync(Apiurl + "/" + jobLogId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{jobLogId.ToString()}"); } public async Task AddJobLogAsync(JobLog joblog) @@ -44,11 +44,11 @@ namespace Oqtane.Services public async Task UpdateJobLogAsync(JobLog joblog) { - return await _http.PutJsonAsync(Apiurl + "/" + joblog.JobLogId.ToString(), joblog); + return await _http.PutJsonAsync($"{Apiurl}/{joblog.JobLogId.ToString()}", joblog); } public async Task DeleteJobLogAsync(int jobLogId) { - await _http.DeleteAsync(Apiurl + "/" + jobLogId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{jobLogId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/JobService.cs b/Oqtane.Client/Services/JobService.cs index 87a2d70c..b06b2fd7 100644 --- a/Oqtane.Client/Services/JobService.cs +++ b/Oqtane.Client/Services/JobService.cs @@ -34,7 +34,7 @@ namespace Oqtane.Services public async Task GetJobAsync(int jobId) { - return await _http.GetJsonAsync(Apiurl + "/" + jobId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{jobId.ToString()}"); } public async Task AddJobAsync(Job job) @@ -44,21 +44,21 @@ namespace Oqtane.Services public async Task UpdateJobAsync(Job job) { - return await _http.PutJsonAsync(Apiurl + "/" + job.JobId.ToString(), job); + return await _http.PutJsonAsync($"{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()}"); } } } diff --git a/Oqtane.Client/Services/LogService.cs b/Oqtane.Client/Services/LogService.cs index 95f718b1..a679ee3d 100644 --- a/Oqtane.Client/Services/LogService.cs +++ b/Oqtane.Client/Services/LogService.cs @@ -30,12 +30,12 @@ namespace Oqtane.Services public async Task> GetLogsAsync(int siteId, string level, string function, int rows) { - return await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString() + "&level=" + level + "&function=" + function + "&rows=" + rows.ToString()); + return await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}&level={level}&function={function}&rows={rows.ToString()}"); } public async Task GetLogAsync(int logId) { - return await _http.GetJsonAsync(Apiurl + "/" + logId.ToString()); + return await _http.GetJsonAsync($"{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) diff --git a/Oqtane.Client/Services/ModuleDefinitionService.cs b/Oqtane.Client/Services/ModuleDefinitionService.cs index cc537e86..119aa9dd 100644 --- a/Oqtane.Client/Services/ModuleDefinitionService.cs +++ b/Oqtane.Client/Services/ModuleDefinitionService.cs @@ -31,28 +31,28 @@ namespace Oqtane.Services public async Task> GetModuleDefinitionsAsync(int siteId) { - List moduledefinitions = await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString()); + List moduledefinitions = await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}"); return moduledefinitions.OrderBy(item => item.Name).ToList(); } public async Task GetModuleDefinitionAsync(int moduleDefinitionId, int siteId) { - return await _http.GetJsonAsync(Apiurl + "/" + moduleDefinitionId.ToString() + "?siteid=" + siteId.ToString()); + return await _http.GetJsonAsync($"{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>(Apiurl + "/install"); + await _http.GetJsonAsync>($"{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); } } } diff --git a/Oqtane.Client/Services/ModuleService.cs b/Oqtane.Client/Services/ModuleService.cs index 2393abaa..c78403e4 100644 --- a/Oqtane.Client/Services/ModuleService.cs +++ b/Oqtane.Client/Services/ModuleService.cs @@ -28,7 +28,7 @@ namespace Oqtane.Services public async Task> GetModulesAsync(int siteId) { - List modules = await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString()); + List modules = await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}"); modules = modules .OrderBy(item => item.Order) .ToList(); @@ -37,7 +37,7 @@ namespace Oqtane.Services public async Task GetModuleAsync(int moduleId) { - return await _http.GetJsonAsync(Apiurl + "/" + moduleId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{moduleId.ToString()}"); } public async Task AddModuleAsync(Module module) @@ -47,22 +47,22 @@ namespace Oqtane.Services public async Task UpdateModuleAsync(Module module) { - return await _http.PutJsonAsync(Apiurl + "/" + module.ModuleId.ToString(), module); + return await _http.PutJsonAsync($"{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 ImportModuleAsync(int moduleId, string content) { - return await _http.PostJsonAsync(Apiurl + "/import?moduleid=" + moduleId, content); + return await _http.PostJsonAsync($"{Apiurl}/import?moduleid={moduleId}", content); } public async Task ExportModuleAsync(int moduleId) { - return await _http.GetStringAsync(Apiurl + "/export?moduleid=" + moduleId.ToString()); + return await _http.GetStringAsync($"{Apiurl}/export?moduleid={moduleId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/NotificationService.cs b/Oqtane.Client/Services/NotificationService.cs index 1e361e24..6239ca8a 100644 --- a/Oqtane.Client/Services/NotificationService.cs +++ b/Oqtane.Client/Services/NotificationService.cs @@ -28,14 +28,14 @@ namespace Oqtane.Services public async Task> GetNotificationsAsync(int siteId, string direction, int userId) { - string querystring = "?siteid=" + siteId.ToString() + "&direction=" + direction.ToLower() + "&userid=" + userId.ToString(); - List notifications = await _http.GetJsonAsync>(Apiurl + querystring); + var notifications = await _http.GetJsonAsync>($"{Apiurl}? siteid={siteId.ToString()}&direction={direction.ToLower()}&userid={userId.ToString()}"); + return notifications.OrderByDescending(item => item.CreatedOn).ToList(); } public async Task GetNotificationAsync(int notificationId) { - return await _http.GetJsonAsync(Apiurl + "/" + notificationId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{notificationId.ToString()}"); } public async Task AddNotificationAsync(Notification notification) @@ -45,11 +45,11 @@ namespace Oqtane.Services public async Task UpdateNotificationAsync(Notification notification) { - return await _http.PutJsonAsync(Apiurl + "/" + notification.NotificationId.ToString(), notification); + return await _http.PutJsonAsync($"{Apiurl}/{notification.NotificationId.ToString()}", notification); } public async Task DeleteNotificationAsync(int notificationId) { - await _http.DeleteAsync(Apiurl + "/" + notificationId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{notificationId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/PackageService.cs b/Oqtane.Client/Services/PackageService.cs index 61c277e1..952ea4cb 100644 --- a/Oqtane.Client/Services/PackageService.cs +++ b/Oqtane.Client/Services/PackageService.cs @@ -28,13 +28,13 @@ namespace Oqtane.Services public async Task> GetPackagesAsync(string tag) { - List packages = await _http.GetJsonAsync>(Apiurl + "?tag=" + tag); + List packages = await _http.GetJsonAsync>($"{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); } } } diff --git a/Oqtane.Client/Services/PageModuleService.cs b/Oqtane.Client/Services/PageModuleService.cs index fdf610ed..11fece8c 100644 --- a/Oqtane.Client/Services/PageModuleService.cs +++ b/Oqtane.Client/Services/PageModuleService.cs @@ -26,12 +26,12 @@ namespace Oqtane.Services public async Task GetPageModuleAsync(int pageModuleId) { - return await _http.GetJsonAsync(Apiurl + "/" + pageModuleId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{pageModuleId.ToString()}"); } public async Task GetPageModuleAsync(int pageId, int moduleId) { - return await _http.GetJsonAsync(Apiurl + "/" + pageId.ToString() + "/" + moduleId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{pageId.ToString()}/{moduleId.ToString()}"); } public async Task AddPageModuleAsync(PageModule pageModule) @@ -41,17 +41,17 @@ namespace Oqtane.Services public async Task UpdatePageModuleAsync(PageModule pageModule) { - return await _http.PutJsonAsync(Apiurl + "/" + pageModule.PageModuleId.ToString(), pageModule); + return await _http.PutJsonAsync($"{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()}"); } } } diff --git a/Oqtane.Client/Services/PageService.cs b/Oqtane.Client/Services/PageService.cs index 7479c501..6cc832c7 100644 --- a/Oqtane.Client/Services/PageService.cs +++ b/Oqtane.Client/Services/PageService.cs @@ -30,26 +30,26 @@ namespace Oqtane.Services public async Task> GetPagesAsync(int siteId) { - List pages = await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString()); + List pages = await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}"); pages = GetPagesHierarchy(pages); return pages; } public async Task GetPageAsync(int pageId) { - return await _http.GetJsonAsync(Apiurl + "/" + pageId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{pageId.ToString()}"); } public async Task GetPageAsync(int pageId, int userId) { - return await _http.GetJsonAsync(Apiurl + "/" + pageId.ToString() + "?userid=" + userId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{pageId.ToString()}?userid={userId.ToString()}"); } public async Task GetPageAsync(string path, int siteId) { try { - return await _http.GetJsonAsync(Apiurl + "/path/" + siteId.ToString() + "?path=" + WebUtility.UrlEncode(path)); + return await _http.GetJsonAsync($"{Apiurl}/path/{siteId.ToString()}?path={WebUtility.UrlEncode(path)}"); } catch { @@ -64,22 +64,25 @@ namespace Oqtane.Services public async Task AddPageAsync(int pageId, int userId) { - return await _http.PostJsonAsync(Apiurl + "/" + pageId.ToString() + "?userid=" + userId.ToString(), null); + return await _http.PostJsonAsync($"{Apiurl}/{pageId.ToString()}?userid={userId.ToString()}", null); } public async Task UpdatePageAsync(Page page) { - return await _http.PutJsonAsync(Apiurl + "/" + page.PageId.ToString(), page); + return await _http.PutJsonAsync($"{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 GetPagesHierarchy(List pages) diff --git a/Oqtane.Client/Services/ProfileService.cs b/Oqtane.Client/Services/ProfileService.cs index f2955a78..4ceb4cac 100644 --- a/Oqtane.Client/Services/ProfileService.cs +++ b/Oqtane.Client/Services/ProfileService.cs @@ -28,13 +28,13 @@ namespace Oqtane.Services public async Task> GetProfilesAsync(int siteId) { - List profiles = await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString()); + List profiles = await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}"); return profiles.OrderBy(item => item.ViewOrder).ToList(); } public async Task GetProfileAsync(int profileId) { - return await _http.GetJsonAsync(Apiurl + "/" + profileId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{profileId.ToString()}"); } public async Task AddProfileAsync(Profile profile) @@ -44,11 +44,11 @@ namespace Oqtane.Services public async Task UpdateProfileAsync(Profile profile) { - return await _http.PutJsonAsync(Apiurl + "/" + profile.SiteId.ToString(), profile); + return await _http.PutJsonAsync($"{Apiurl}/{profile.SiteId.ToString()}", profile); } public async Task DeleteProfileAsync(int profileId) { - await _http.DeleteAsync(Apiurl + "/" + profileId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{profileId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/RoleService.cs b/Oqtane.Client/Services/RoleService.cs index 7328cbbb..708f0721 100644 --- a/Oqtane.Client/Services/RoleService.cs +++ b/Oqtane.Client/Services/RoleService.cs @@ -28,13 +28,13 @@ namespace Oqtane.Services public async Task> GetRolesAsync(int siteId) { - List roles = await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString()); + List roles = await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}"); return roles.OrderBy(item => item.Name).ToList(); } public async Task GetRoleAsync(int roleId) { - return await _http.GetJsonAsync(Apiurl + "/" + roleId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{roleId.ToString()}"); } public async Task AddRoleAsync(Role role) @@ -44,11 +44,11 @@ namespace Oqtane.Services public async Task UpdateRoleAsync(Role role) { - return await _http.PutJsonAsync(Apiurl + "/" + role.RoleId.ToString(), role); + return await _http.PutJsonAsync($"{Apiurl}/{role.RoleId.ToString()}", role); } public async Task DeleteRoleAsync(int roleId) { - await _http.DeleteAsync(Apiurl + "/" + roleId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{roleId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/ServiceBase.cs b/Oqtane.Client/Services/ServiceBase.cs index f8a6e767..13b5e1c6 100644 --- a/Oqtane.Client/Services/ServiceBase.cs +++ b/Oqtane.Client/Services/ServiceBase.cs @@ -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; } diff --git a/Oqtane.Client/Services/SettingService.cs b/Oqtane.Client/Services/SettingService.cs index d52878c8..22ac7fc4 100644 --- a/Oqtane.Client/Services/SettingService.cs +++ b/Oqtane.Client/Services/SettingService.cs @@ -98,8 +98,9 @@ namespace Oqtane.Services public async Task> GetSettingsAsync(string entityName, int entityId) { - Dictionary dictionary = new Dictionary(); - List settings = await _http.GetJsonAsync>(Apiurl + "?entityname=" + entityName + "&entityid=" + entityId.ToString()); + var dictionary = new Dictionary(); + var settings = await _http.GetJsonAsync>($"{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 settings, string entityName, int entityId) { - List settingsList = await _http.GetJsonAsync>(Apiurl + "?entityname=" + entityName + "&entityid=" + entityId.ToString()); + var settingsList = await _http.GetJsonAsync>($"{Apiurl}?entityname={entityName}&entityid={entityId.ToString()}"); + foreach (KeyValuePair kvp in settings) { Setting setting = settingsList.FirstOrDefault(item => item.SettingName == kvp.Key); @@ -136,7 +138,7 @@ namespace Oqtane.Services public async Task GetSettingAsync(int settingId) { - return await _http.GetJsonAsync(Apiurl + "/" + settingId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{settingId.ToString()}"); } public async Task AddSettingAsync(Setting setting) @@ -146,12 +148,12 @@ namespace Oqtane.Services public async Task UpdateSettingAsync(Setting setting) { - return await _http.PutJsonAsync(Apiurl + "/" + setting.SettingId.ToString(), setting); + return await _http.PutJsonAsync($"{Apiurl}/{setting.SettingId.ToString()}", setting); } public async Task DeleteSettingAsync(int settingId) { - await _http.DeleteAsync(Apiurl + "/" + settingId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{settingId.ToString()}"); } diff --git a/Oqtane.Client/Services/SiteService.cs b/Oqtane.Client/Services/SiteService.cs index 0735f8e1..ce4a379c 100644 --- a/Oqtane.Client/Services/SiteService.cs +++ b/Oqtane.Client/Services/SiteService.cs @@ -34,7 +34,7 @@ namespace Oqtane.Services public async Task GetSiteAsync(int siteId, Alias alias) { - return await _http.GetJsonAsync(CreateCrossTenantUrl(Apiurl + "/" + siteId.ToString(), alias)); + return await _http.GetJsonAsync(CreateCrossTenantUrl($"{Apiurl}/{siteId.ToString()}", alias)); } public async Task AddSiteAsync(Site site, Alias alias) @@ -44,12 +44,12 @@ namespace Oqtane.Services public async Task UpdateSiteAsync(Site site, Alias alias) { - return await _http.PutJsonAsync(CreateCrossTenantUrl(Apiurl + "/" + site.SiteId.ToString(), alias), site); + return await _http.PutJsonAsync(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)); } } } diff --git a/Oqtane.Client/Services/TenantService.cs b/Oqtane.Client/Services/TenantService.cs index 54edb128..d325fd91 100644 --- a/Oqtane.Client/Services/TenantService.cs +++ b/Oqtane.Client/Services/TenantService.cs @@ -34,7 +34,7 @@ namespace Oqtane.Services public async Task GetTenantAsync(int tenantId) { - return await _http.GetJsonAsync(Apiurl + "/" + tenantId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{tenantId.ToString()}"); } public async Task AddTenantAsync(Tenant tenant) @@ -44,12 +44,12 @@ namespace Oqtane.Services public async Task UpdateTenantAsync(Tenant tenant) { - return await _http.PutJsonAsync(Apiurl + "/" + tenant.TenantId.ToString(), tenant); + return await _http.PutJsonAsync($"{Apiurl}/{tenant.TenantId.ToString()}", tenant); } public async Task DeleteTenantAsync(int tenantId) { - await _http.DeleteAsync(Apiurl + "/" + tenantId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{tenantId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/ThemeService.cs b/Oqtane.Client/Services/ThemeService.cs index e3d5e2a3..e872aae1 100644 --- a/Oqtane.Client/Services/ThemeService.cs +++ b/Oqtane.Client/Services/ThemeService.cs @@ -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>(Apiurl + "/install"); + await _http.GetJsonAsync>($"{Apiurl}/install"); } public async Task DeleteThemeAsync(string themeName) { - await _http.DeleteAsync(Apiurl + "/" + themeName); + await _http.DeleteAsync($"{Apiurl}/{themeName}"); } } } diff --git a/Oqtane.Client/Services/UserRoleService.cs b/Oqtane.Client/Services/UserRoleService.cs index d45a000c..66e9feb9 100644 --- a/Oqtane.Client/Services/UserRoleService.cs +++ b/Oqtane.Client/Services/UserRoleService.cs @@ -27,12 +27,12 @@ namespace Oqtane.Services public async Task> GetUserRolesAsync(int siteId) { - return await _http.GetJsonAsync>(Apiurl + "?siteid=" + siteId.ToString()); + return await _http.GetJsonAsync>($"{Apiurl}?siteid={siteId.ToString()}"); } public async Task GetUserRoleAsync(int userRoleId) { - return await _http.GetJsonAsync(Apiurl + "/" + userRoleId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{userRoleId.ToString()}"); } public async Task AddUserRoleAsync(UserRole userRole) @@ -42,12 +42,12 @@ namespace Oqtane.Services public async Task UpdateUserRoleAsync(UserRole userRole) { - return await _http.PutJsonAsync(Apiurl + "/" + userRole.UserRoleId.ToString(), userRole); + return await _http.PutJsonAsync($"{Apiurl}/{userRole.UserRoleId.ToString()}", userRole); } public async Task DeleteUserRoleAsync(int userRoleId) { - await _http.DeleteAsync(Apiurl + "/" + userRoleId.ToString()); + await _http.DeleteAsync($"{Apiurl}/{userRoleId.ToString()}"); } } } diff --git a/Oqtane.Client/Services/UserService.cs b/Oqtane.Client/Services/UserService.cs index 43bc3ec4..d81077ff 100644 --- a/Oqtane.Client/Services/UserService.cs +++ b/Oqtane.Client/Services/UserService.cs @@ -26,12 +26,12 @@ namespace Oqtane.Services public async Task GetUserAsync(int userId, int siteId) { - return await _http.GetJsonAsync(Apiurl + "/" + userId.ToString() + "?siteid=" + siteId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/{userId.ToString()}?siteid={siteId.ToString()}"); } public async Task GetUserAsync(string username, int siteId) { - return await _http.GetJsonAsync(Apiurl + "/name/" + username + "?siteid=" + siteId.ToString()); + return await _http.GetJsonAsync($"{Apiurl}/name/{username}?siteid={siteId.ToString()}"); } public async Task AddUserAsync(User user) @@ -60,37 +60,37 @@ namespace Oqtane.Services public async Task UpdateUserAsync(User user) { - return await _http.PutJsonAsync(Apiurl + "/" + user.UserId.ToString(), user); + return await _http.PutJsonAsync($"{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 LoginUserAsync(User user, bool setCookie, bool isPersistent) { - return await _http.PostJsonAsync(Apiurl + "/login?setcookie=" + setCookie.ToString() + "&persistent=" + isPersistent.ToString(), user); + return await _http.PostJsonAsync($"{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 VerifyEmailAsync(User user, string token) { - return await _http.PostJsonAsync(Apiurl + "/verify?token=" + token, user); + return await _http.PostJsonAsync($"{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 ResetPasswordAsync(User user, string token) { - return await _http.PostJsonAsync(Apiurl + "/reset?token=" + token, user); + return await _http.PostJsonAsync($"{Apiurl}/reset?token={token}", user); } }