mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
Using to MinimalAPI
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.
This commit is contained in:
64
WebApp/Mapping/EventMapping.cs
Normal file
64
WebApp/Mapping/EventMapping.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user