mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
103 lines
3.3 KiB
C#
103 lines
3.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using WebApp.DTOs;
|
|
using WebApp.Entities;
|
|
|
|
namespace WebApp.Mapping;
|
|
|
|
public static class EventMapping
|
|
{
|
|
public static Event ToEntity(this EventCreateDto ECDto)
|
|
{
|
|
return new Event()
|
|
{
|
|
Title = ECDto.Title,
|
|
Description = ECDto.Description,
|
|
Location = ECDto.Location,
|
|
EventDate = DateTime.SpecifyKind(ECDto.EventDate!.Value, DateTimeKind.Utc),
|
|
EventSkills = ECDto.EventSkills,
|
|
EventRegistrations = []
|
|
};
|
|
}
|
|
|
|
public static Event ToEntity(this EventUpdateDto EUDto, int id)
|
|
{
|
|
return new Event()
|
|
{
|
|
EventId = id,
|
|
Title = EUDto.Title,
|
|
Description = EUDto.Description,
|
|
Location = EUDto.Location,
|
|
EventDate = DateTime.SpecifyKind(EUDto.EventDate!.Value, DateTimeKind.Utc),
|
|
EventSkills = EUDto.EventSkills
|
|
};
|
|
}
|
|
|
|
public static EventSummaryDto ToEventSummaryDto(this Event myEvent)
|
|
{
|
|
return new EventSummaryDto {
|
|
EventId = myEvent.EventId,
|
|
Organisation = myEvent.Organisation!.Name,
|
|
OrganisationId = myEvent.OrganisationId,
|
|
Title = myEvent.Title,
|
|
Description = myEvent.Description,
|
|
Location = myEvent.Location,
|
|
EventDate = myEvent.EventDate,
|
|
EventSkills = myEvent.EventSkills,
|
|
EventRegistrations = myEvent.EventRegistrations
|
|
};
|
|
}
|
|
public static EventSummaryNoErDto ToEventSummaryNoErDto(this Event myEvent)
|
|
{
|
|
|
|
return new EventSummaryNoErDto(
|
|
myEvent.EventId,
|
|
myEvent.Organisation!.Name,
|
|
myEvent.OrganisationId,
|
|
myEvent.Title,
|
|
myEvent.Description,
|
|
myEvent.Location,
|
|
myEvent.EventDate,
|
|
myEvent.EventSkills
|
|
);
|
|
}
|
|
|
|
public static EventRegistrationDto ToEventRegistrationDto(this EventRegistration myER)
|
|
{
|
|
|
|
return new EventRegistrationDto {
|
|
EventId = myER.EventId,
|
|
UserId = myER.UserId,
|
|
UserName = myER.User.FirstName + " " + myER.User.LastName,
|
|
RegisteredAt = myER.RegisteredAt
|
|
};
|
|
}
|
|
|
|
public static EventDetailsDto ToEventDetailsDto(this Event myEvent)
|
|
{
|
|
List<SkillSummaryDto> ssdto = new List<SkillSummaryDto>();
|
|
List<EventRegistrationDto> erdto = new List<EventRegistrationDto>();
|
|
|
|
foreach (EventSkill es in myEvent.EventSkills)
|
|
{
|
|
ssdto.Add(es.ToSkillSummaryDto());
|
|
}
|
|
|
|
foreach (EventRegistration er in myEvent.EventRegistrations)
|
|
{
|
|
erdto.Add(er.ToEventRegistrationDto());
|
|
}
|
|
|
|
return new EventDetailsDto {
|
|
EventId = myEvent.EventId,
|
|
OrganisationId = myEvent.OrganisationId,
|
|
OrganisationName = myEvent.Organisation.Name,
|
|
Title = myEvent.Title,
|
|
Description = myEvent.Description,
|
|
Location = myEvent.Location,
|
|
EventDate = myEvent.EventDate,
|
|
EventSkills = ssdto,
|
|
EventRegistrations = erdto
|
|
};
|
|
}
|
|
}
|