using Oqtane.Models; using System.Threading.Tasks; using System.Net.Http; using System.Linq; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using Oqtane.Shared; namespace Oqtane.Services { public class ScheduleService : ServiceBase, IScheduleService { private readonly HttpClient http; private readonly SiteState sitestate; private readonly NavigationManager NavigationManager; public ScheduleService(HttpClient http, SiteState sitestate, NavigationManager NavigationManager) { this.http = http; this.sitestate = sitestate; this.NavigationManager = NavigationManager; } private string apiurl { get { return CreateApiUrl(sitestate.Alias, NavigationManager.Uri, "Schedule"); } } public async Task> GetSchedulesAsync() { List schedules = await http.GetJsonAsync>(apiurl); return schedules.OrderBy(item => item.Name).ToList(); } public async Task GetScheduleAsync(int ScheduleId) { return await http.GetJsonAsync(apiurl + "/" + ScheduleId.ToString()); } public async Task AddScheduleAsync(Schedule schedule) { return await http.PostJsonAsync(apiurl, schedule); } public async Task UpdateScheduleAsync(Schedule schedule) { return await http.PutJsonAsync(apiurl + "/" + schedule.ScheduleId.ToString(), schedule); } public async Task DeleteScheduleAsync(int ScheduleId) { await http.DeleteAsync(apiurl + "/" + ScheduleId.ToString()); } } }