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
22 changed files with 124 additions and 108 deletions

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)