Migration to using System.Net.Http.Json; part one - functional migration

This commit is contained in:
Pavel Vesely
2020-04-15 23:03:37 +02:00
parent fe2ad29b3b
commit 95e9bee4e2
29 changed files with 293 additions and 215 deletions

View File

@ -10,13 +10,11 @@ namespace Oqtane.Services
{
public class NotificationService : ServiceBase, INotificationService
{
private readonly HttpClient _http;
private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager;
public NotificationService(HttpClient http, SiteState siteState, NavigationManager navigationManager)
public NotificationService(HttpClient http, SiteState siteState, NavigationManager navigationManager) : base(http)
{
_http = http;
_siteState = siteState;
_navigationManager = navigationManager;
}
@ -28,28 +26,29 @@ namespace Oqtane.Services
public async Task<List<Notification>> GetNotificationsAsync(int siteId, string direction, int userId)
{
var notifications = await _http.GetJsonAsync<List<Notification>>($"{Apiurl}?siteid={siteId.ToString()}&direction={direction.ToLower()}&userid={userId.ToString()}");
var notifications = await 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 GetJsonAsync<Notification>($"{Apiurl}/{notificationId.ToString()}");
}
public async Task<Notification> AddNotificationAsync(Notification notification)
{
return await _http.PostJsonAsync<Notification>(Apiurl, notification);
return await PostJsonAsync<Notification>(Apiurl, notification);
}
public async Task<Notification> UpdateNotificationAsync(Notification notification)
{
return await _http.PutJsonAsync<Notification>($"{Apiurl}/{notification.NotificationId.ToString()}", notification);
return await PutJsonAsync<Notification>($"{Apiurl}/{notification.NotificationId.ToString()}", notification);
}
public async Task DeleteNotificationAsync(int notificationId)
{
await _http.DeleteAsync($"{Apiurl}/{notificationId.ToString()}");
await DeleteAsync($"{Apiurl}/{notificationId.ToString()}");
}
}
}