mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 13:40:13 +01:00
Usunalem EventApiController(dobry byl ale mial problemy). Dodalem EventsEndpoints, zawiera async, używa Dtos (Data Transfer Objects). Jeżeli chcecie zrobić HTTP request ale nie wiecie co dać w body JSONa to można sprawdzić w tych Dtos. EventMapping służy do zmian obiektów Dto na Entity i odwrotnie.
64 lines
1.8 KiB
C#
64 lines
1.8 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()
|
|
{
|
|
OrganisationId = ECDto.OrganisationId!.Value,
|
|
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,
|
|
OrganisationId = EUDto.OrganisationId!.Value,
|
|
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(
|
|
myEvent.EventId,
|
|
myEvent.Organisation!.Name,
|
|
myEvent.Title,
|
|
myEvent.Description,
|
|
myEvent.Location,
|
|
myEvent.EventDate,
|
|
myEvent.EventSkills,
|
|
myEvent.EventRegistrations
|
|
);
|
|
}
|
|
|
|
public static EventDetailsDto ToEventDetailsDto(this Event myEvent)
|
|
{
|
|
return new EventDetailsDto(
|
|
myEvent.EventId,
|
|
myEvent.OrganisationId,
|
|
myEvent.Title,
|
|
myEvent.Description,
|
|
myEvent.Location,
|
|
myEvent.EventDate,
|
|
myEvent.EventSkills,
|
|
myEvent.EventRegistrations
|
|
);
|
|
}
|
|
} |