From c2a8322debb7e25fa44a540d8aa5700a2fad5973 Mon Sep 17 00:00:00 2001 From: Owczarek Kamil Date: Mon, 10 Jun 2024 13:52:31 +0200 Subject: [PATCH] Slug creating method updated --- .../ReasnAPI/ReasnAPI/Services/EventService.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Server/ReasnAPI/ReasnAPI/Services/EventService.cs b/Server/ReasnAPI/ReasnAPI/Services/EventService.cs index d4792269..8eb7dbae 100644 --- a/Server/ReasnAPI/ReasnAPI/Services/EventService.cs +++ b/Server/ReasnAPI/ReasnAPI/Services/EventService.cs @@ -15,12 +15,13 @@ public EventDto CreateEvent(EventDto eventDto) { using (var scope = new TransactionScope()) { - eventDto.Slug = CreateSlug(eventDto); - var nowTime = DateTime.UtcNow; + + var createdTime = DateTime.UtcNow; var newEvent = eventDto.ToEntity(); - newEvent.CreatedAt = nowTime; - newEvent.UpdatedAt = nowTime; - newEvent.Slug = eventDto.Slug; + newEvent.CreatedAt = createdTime; + newEvent.UpdatedAt = createdTime; + newEvent.Slug = CreateSlug(eventDto, createdTime); + context.Events.Add(newEvent); context.SaveChanges(); @@ -230,10 +231,11 @@ public IEnumerable GetAllEvents() return eventDtos; } - private string CreateSlug(EventDto eventDto) + private string CreateSlug(EventDto eventDto, DateTime createdTime) { var slug = eventDto.Name.ToLower().Replace(" ", "-"); - return slug; + var timestamp = createdTime.Ticks; + return $"{slug}-{timestamp}"; } } \ No newline at end of file