fixed user registration, and updated module creator templates to use new Service approach

This commit is contained in:
Shaun Walker
2020-04-16 10:21:16 -04:00
parent 3d21a6e204
commit f5e4c1dd29
8 changed files with 223 additions and 151 deletions

View File

@ -12,13 +12,11 @@ namespace [Owner].[Module]s.Services
{
public class [Module]Service : ServiceBase, I[Module]Service, IService
{
private readonly HttpClient _http;
private readonly NavigationManager _navigationManager;
private readonly SiteState _siteState;
public [Module]Service(HttpClient http, SiteState siteState, NavigationManager navigationManager)
public [Module]Service(HttpClient http, SiteState siteState, NavigationManager navigationManager) : base(http)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
}
@ -30,28 +28,28 @@ namespace [Owner].[Module]s.Services
public async Task<List<[Module]>> Get[Module]sAsync(int ModuleId)
{
List<[Module]> [Module]s = await _http.GetJsonAsync<List<[Module]>>(Apiurl + "?moduleid=" + ModuleId.ToString());
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>(Apiurl + "?moduleid=" + ModuleId.ToString());
return [Module]s.OrderBy(item => item.Name).ToList();
}
public async Task<[Module]> Get[Module]Async(int [Module]Id)
{
return await _http.GetJsonAsync<[Module]>(Apiurl + "/" + [Module]Id.ToString());
return await GetJsonAsync<[Module]>(Apiurl + "/" + [Module]Id.ToString());
}
public async Task<[Module]> Add[Module]Async([Module] [Module])
{
return await _http.PostJsonAsync<[Module]>(Apiurl + "?entityid=" + [Module].ModuleId, [Module]);
return await PostJsonAsync<[Module]>(Apiurl + "?entityid=" + [Module].ModuleId, [Module]);
}
public async Task<[Module]> Update[Module]Async([Module] [Module])
{
return await _http.PutJsonAsync<[Module]>(Apiurl + "/" + [Module].[Module]Id + "?entityid=" + [Module].ModuleId, [Module]);
return await PutJsonAsync<[Module]>(Apiurl + "/" + [Module].[Module]Id + "?entityid=" + [Module].ModuleId, [Module]);
}
public async Task Delete[Module]Async(int [Module]Id)
{
await _http.DeleteAsync(Apiurl + "/" + [Module]Id.ToString());
await DeleteAsync(Apiurl + "/" + [Module]Id.ToString());
}
}
}

View File

@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview3.20175.8" />
</ItemGroup>
<ItemGroup>

View File

@ -12,13 +12,11 @@ namespace [Owner].[Module]s.Services
{
public class [Module]Service : ServiceBase, I[Module]Service, IService
{
private readonly HttpClient _http;
private readonly NavigationManager _navigationManager;
private readonly SiteState _siteState;
public [Module]Service(HttpClient http, SiteState siteState, NavigationManager navigationManager)
public [Module]Service(HttpClient http, SiteState siteState, NavigationManager navigationManager) : base(http)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
}
@ -30,28 +28,28 @@ namespace [Owner].[Module]s.Services
public async Task<List<[Module]>> Get[Module]sAsync(int ModuleId)
{
List<[Module]> [Module]s = await _http.GetJsonAsync<List<[Module]>>(Apiurl + "?moduleid=" + ModuleId.ToString());
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>(Apiurl + "?moduleid=" + ModuleId.ToString());
return [Module]s.OrderBy(item => item.Name).ToList();
}
public async Task<[Module]> Get[Module]Async(int [Module]Id)
{
return await _http.GetJsonAsync<[Module]>(Apiurl + "/" + [Module]Id.ToString());
return await GetJsonAsync<[Module]>(Apiurl + "/" + [Module]Id.ToString());
}
public async Task<[Module]> Add[Module]Async([Module] [Module])
{
return await _http.PostJsonAsync<[Module]>(Apiurl + "?entityid=" + [Module].ModuleId, [Module]);
return await PostJsonAsync<[Module]>(Apiurl + "?entityid=" + [Module].ModuleId, [Module]);
}
public async Task<[Module]> Update[Module]Async([Module] [Module])
{
return await _http.PutJsonAsync<[Module]>(Apiurl + "/" + [Module].[Module]Id + "?entityid=" + [Module].ModuleId, [Module]);
return await PutJsonAsync<[Module]>(Apiurl + "/" + [Module].[Module]Id + "?entityid=" + [Module].ModuleId, [Module]);
}
public async Task Delete[Module]Async(int [Module]Id)
{
await _http.DeleteAsync(Apiurl + "/" + [Module]Id.ToString());
await DeleteAsync(Apiurl + "/" + [Module]Id.ToString());
}
}
}