101 lines
3.8 KiB
C#
101 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using Oqtane.Modules;
|
|
using Oqtane.Models;
|
|
using Oqtane.Infrastructure;
|
|
using Oqtane.Interfaces;
|
|
using Oqtane.Enums;
|
|
using Oqtane.Repository;
|
|
using SZUAbsolventenverein.Module.EventRegistration.Repository;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SZUAbsolventenverein.Module.EventRegistration.Manager
|
|
{
|
|
public class EventRegistrationManager : MigratableModuleBase, IInstallable, IPortable, ISearchable
|
|
{
|
|
private readonly IEventRepository _EventRepository;
|
|
private readonly IResponseRepository _ResponseRepository;
|
|
private readonly IDBContextDependencies _DBContextDependencies;
|
|
|
|
public EventRegistrationManager(IEventRepository EventRegistrationRepository, IResponseRepository ResponseRepository, IDBContextDependencies DBContextDependencies)
|
|
{
|
|
_EventRepository = EventRegistrationRepository;
|
|
_ResponseRepository = ResponseRepository;
|
|
_DBContextDependencies = DBContextDependencies;
|
|
}
|
|
|
|
public bool Install(Tenant tenant, string version)
|
|
{
|
|
return Migrate(new EventRegistrationContext(_DBContextDependencies), tenant, MigrationType.Up);
|
|
}
|
|
|
|
public bool Uninstall(Tenant tenant)
|
|
{
|
|
return Migrate(new EventRegistrationContext(_DBContextDependencies), tenant, MigrationType.Down);
|
|
}
|
|
|
|
public string ExportModule(Oqtane.Models.Module module)
|
|
{
|
|
// TODO: Export event Responses as well.
|
|
string content = "";
|
|
List<object> exportData = new List<object>();
|
|
foreach (var events in _EventRepository.GetEvents(module.ModuleId))
|
|
{
|
|
var responses = _ResponseRepository.GetResponses(events.EventId, module.ModuleId);
|
|
exportData.Add(new
|
|
{
|
|
Event = events,
|
|
Responses = responses.ToList()
|
|
});
|
|
};
|
|
if (exportData != null)
|
|
{
|
|
content = JsonSerializer.Serialize(exportData);
|
|
}
|
|
return content;
|
|
}
|
|
|
|
public void ImportModule(Oqtane.Models.Module module, string content, string version)
|
|
{
|
|
// TODO: Import event Responses as well.
|
|
List<Models.Event> EventRegistrations = null;
|
|
if (!string.IsNullOrEmpty(content))
|
|
{
|
|
EventRegistrations = JsonSerializer.Deserialize<List<Models.Event>>(content);
|
|
}
|
|
if (EventRegistrations != null)
|
|
{
|
|
foreach(var EventRegistration in EventRegistrations)
|
|
{
|
|
_EventRepository.AddEvent(new Models.Event { ModuleId = module.ModuleId, Name = EventRegistration.Name });
|
|
}
|
|
}
|
|
}
|
|
|
|
public Task<List<SearchContent>> GetSearchContentsAsync(PageModule pageModule, DateTime lastIndexedOn)
|
|
{
|
|
var searchContentList = new List<SearchContent>();
|
|
|
|
foreach (var EventRegistration in _EventRepository.GetEvents(pageModule.ModuleId))
|
|
{
|
|
if (EventRegistration.ModifiedOn >= lastIndexedOn)
|
|
{
|
|
searchContentList.Add(new SearchContent
|
|
{
|
|
EntityName = "SZUAbsolventenvereinEventRegistration",
|
|
EntityId = EventRegistration.EventId.ToString(),
|
|
Title = EventRegistration.Name,
|
|
Body = EventRegistration.Name,
|
|
ContentModifiedBy = EventRegistration.ModifiedBy,
|
|
ContentModifiedOn = EventRegistration.ModifiedOn
|
|
});
|
|
}
|
|
}
|
|
|
|
return Task.FromResult(searchContentList);
|
|
}
|
|
}
|
|
}
|