Skip to content

Commit

Permalink
updated services
Browse files Browse the repository at this point in the history
  • Loading branch information
bilimig committed Jun 10, 2024
1 parent e422556 commit 6b03b48
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
20 changes: 18 additions & 2 deletions Server/ReasnAPI/ReasnAPI/Services/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public EventDto UpdateEvent(int eventId, EventDto eventDto)
{
using (var scope = new TransactionScope())
{
var eventToUpdate = context.Events.FirstOrDefault(r => r.Id == eventId);
var eventToUpdate = context.Events.Include(e => e.Tags).Include(e => e.Parameters).FirstOrDefault(e => e.Id == eventId);

if (eventToUpdate is null)
{
Expand Down Expand Up @@ -159,13 +159,29 @@ public void DeleteEvent(int eventId)
{
using (var scope = new TransactionScope())
{
var eventToDelete = context.Events.FirstOrDefault(r => r.Id == eventId);
var eventToDelete = context.Events.Include(e => e.Tags).Include(e => e.Parameters).FirstOrDefault(e => e.Id == eventId);

if (eventToDelete is null)
{
throw new NotFoundException("Event not found");
}

foreach (var tag in eventToDelete.Tags.ToList())
{
if (!context.Events.Any(e => e.Tags.Any(t => t.Name == tag.Name) && e.Id != eventId))
{
context.Tags.Remove(tag);
}
}

foreach (var parameter in eventToDelete.Parameters.ToList())
{
if (!context.Events.Any(e => e.Parameters.Any(p => p.Key == parameter.Key && p.Value == parameter.Value) && e.Id != eventId))
{
context.Parameters.Remove(parameter);
}
}

context.Events.Remove(eventToDelete);
context.SaveChanges();
scope.Complete();
Expand Down
4 changes: 2 additions & 2 deletions Server/ReasnAPI/ReasnAPI/Services/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public List<ImageDto> CreateImages(List<ImageDto> imageDtos)

if (newImages.Any())
{
var objectType = newImages.First().ObjectType;
var objectType = newImages[0].ObjectType;


if (objectType == ObjectType.User && newImages.Count == 1)
{
context.Images.Add(newImages.First());
context.Images.Add(newImages[0]);
}
else if (objectType == ObjectType.Event)
{
Expand Down
4 changes: 2 additions & 2 deletions Server/ReasnAPI/ReasnAPI/Services/InterestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void DeleteInterest(int id)
throw new NotFoundException("Interest not found");
}

var eventInterest = context.UserInterests.FirstOrDefault(r => r.InterestId == id);
if (eventInterest is not null)
var userInterest = context.UserInterests.FirstOrDefault(r => r.InterestId == id);
if (userInterest is not null)
{
throw new BadRequestException("Interest is in use");
}
Expand Down

0 comments on commit 6b03b48

Please sign in to comment.