69 lines
3.1 KiB
C#
69 lines
3.1 KiB
C#
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<List<Event>> GetEventsAsync(int ModuleId)
|
|
{
|
|
List<Event> EventRegistrations = await GetJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Event>().ToList());
|
|
return EventRegistrations.OrderBy(item => item.Name).ToList();
|
|
}
|
|
public async Task<Event> GetEventAsync(int EventId, int ModuleId)
|
|
{
|
|
return await GetJsonAsync<Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventId}/{ModuleId}", EntityNames.Module, ModuleId));
|
|
}
|
|
|
|
public async Task<Event> AddEventAsync(Event NewEvent)
|
|
{
|
|
return await PostJsonAsync(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, NewEvent.ModuleId), NewEvent);
|
|
}
|
|
|
|
public async Task<Event> UpdateEventAsync(Event UpdatedEvent)
|
|
{
|
|
return await PutJsonAsync<Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{UpdatedEvent.EventId}", EntityNames.Module, UpdatedEvent.ModuleId), UpdatedEvent);
|
|
}
|
|
|
|
public async Task DeleteEventAsync(int EventId, int ModuleId)
|
|
{
|
|
await DeleteAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventId}/{ModuleId}", EntityNames.Module, ModuleId));
|
|
}
|
|
|
|
public async Task<Response> AddResponseAsync(Response response)
|
|
{
|
|
return await PostJsonAsync<Response>(CreateAuthorizationPolicyUrl($"{Apiurl}/response/{response.EventRegistrationId}/{response.ModuleId}", EntityNames.Module, response.ModuleId), response);
|
|
}
|
|
|
|
public async Task<Response> UpdateResponseAsync(Response response)
|
|
{
|
|
return await PutJsonAsync<Response>(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 async Task<List<Response>> GetEventResponses(int EventId, int ModuleId)
|
|
{
|
|
return await GetJsonAsync<List<Response>>(CreateAuthorizationPolicyUrl($"{Apiurl}/all-responses/{EventId}/{ModuleId}", EntityNames.Module, ModuleId));
|
|
}
|
|
|
|
public Task<List<Response>> GetRecommendedEventResponses(int EventId, int MouleId)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
}
|
|
}
|