using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Oqtane.Services; using Oqtane.Shared; using SZUAbsolventenverein.Module.EventRegistration.Models; namespace SZUAbsolventenverein.Module.EventRegistration.Services { public class EventRegistrationService : ServiceBase, IEventRegistrationService { public EventRegistrationService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string Apiurl => CreateApiUrl("EventRegistration"); /*public async Task> GetEventRegistrationsAsync(int ModuleId) { List EventRegistrations = await GetJsonAsync>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty().ToList()); return EventRegistrations.OrderBy(item => item.Name).ToList(); } public async Task GetEventRegistrationAsync(int EventRegistrationId, int ModuleId) { return await GetJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventRegistrationId}/{ModuleId}", EntityNames.Module, ModuleId)); } public async Task AddEventRegistrationAsync(Models.Event EventRegistration) { return await PostJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, EventRegistration.ModuleId), EventRegistration); } public async Task UpdateEventRegistrationAsync(Models.Event EventRegistration) { return await PutJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventRegistration.EventRegistrationId}", EntityNames.Module, EventRegistration.ModuleId), EventRegistration); }*/ public async Task> GetEventsAsync(int ModuleId) { List EventRegistrations = await GetJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty().ToList()); return EventRegistrations.OrderBy(item => item.Name).ToList(); } public async Task GetEventAsync(int EventId, int ModuleId) { return await GetJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventId}/{ModuleId}", EntityNames.Module, ModuleId)); } public async Task AddEventAsync(Event NewEvent) { return await PostJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, NewEvent.ModuleId), NewEvent); } public async Task UpdateEventAsync(Event NewEvent) { return await PutJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{NewEvent.EventId}", EntityNames.Module, NewEvent.ModuleId), NewEvent); } public async Task DeleteEventAsync(int EventId, int ModuleId) { await DeleteAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventId}/{ModuleId}", EntityNames.Module, ModuleId)); } public async Task AddResponseAsync(Response response) { return await PostJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/response/{response.EventRegistrationId}/{response.ModuleId}", EntityNames.Module, response.ModuleId), response); } public async Task UpdateResponseAsync(Response response) { return await PutJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/response/{response.EventRegistrationId}/{response.ModuleId}", EntityNames.Module, response.ModuleId), response); } public async Task<(Event, Response)> GetEventDetails(int EventId, int ModuleId) { return await GetJsonAsync<(Event, Response)>(CreateAuthorizationPolicyUrl($"{Apiurl}/details/{EventId}/{ModuleId}", EntityNames.Module, ModuleId)); } public Task> GetEventResponses(int EventId, int ModuleId) { throw new System.NotImplementedException(); } } }