
Interface Definition: done Server-Side-Implementation: partly done (CR missing, potential Refactor, ...) Client-Side-Implementation: started: (UI: done, Service: started, but works with SSR) Missing: Permissions / Roles to restrict access to an event. Missing: Fields on Event. Missing: Good Styling Time-Took: about 12 Hours. Learning: Commit in smaller packets, rest will be discussed at CR
85 lines
4.1 KiB
C#
85 lines
4.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<Models.Event>> GetEventRegistrationsAsync(int ModuleId)
|
|
{
|
|
List<Models.Event> EventRegistrations = await GetJsonAsync<List<Models.Event>>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", EntityNames.Module, ModuleId), Enumerable.Empty<Models.Event>().ToList());
|
|
return EventRegistrations.OrderBy(item => item.Name).ToList();
|
|
}
|
|
|
|
public async Task<Models.Event> GetEventRegistrationAsync(int EventRegistrationId, int ModuleId)
|
|
{
|
|
return await GetJsonAsync<Models.Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventRegistrationId}/{ModuleId}", EntityNames.Module, ModuleId));
|
|
}
|
|
|
|
public async Task<Models.Event> AddEventRegistrationAsync(Models.Event EventRegistration)
|
|
{
|
|
return await PostJsonAsync<Models.Event>(CreateAuthorizationPolicyUrl($"{Apiurl}", EntityNames.Module, EventRegistration.ModuleId), EventRegistration);
|
|
}
|
|
|
|
public async Task<Models.Event> UpdateEventRegistrationAsync(Models.Event EventRegistration)
|
|
{
|
|
return await PutJsonAsync<Models.Event>(CreateAuthorizationPolicyUrl($"{Apiurl}/{EventRegistration.EventRegistrationId}", EntityNames.Module, EventRegistration.ModuleId), 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 NewEvent)
|
|
{
|
|
return await PutJsonAsync<Event>(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<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 Task<List<Response>> GetEventResponses(int EventId, int ModuleId)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
}
|
|
}
|