Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bilimig committed Jun 12, 2024
1 parent 631d8b7 commit 9bb1ca6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Services/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public IEnumerable<ParticipantDto> GetEventParticipantsBySlug(string slug)
public IEnumerable<CommentDto> GetEventCommentsBySlug(string slug)
{
var eventToReturn = context.Events.Include(e => e.Comments)
.Include(e => e.Participants).FirstOrDefault(e => e.Slug == slug);
.FirstOrDefault(e => e.Slug == slug);
if (eventToReturn is null)
{
throw new NotFoundException("Event not found");
Expand Down
16 changes: 8 additions & 8 deletions Server/ReasnAPI/ReasnAPI/Services/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void UpdateImageForUser(int userId, ImageDto imageDto)
}

var image = context.Images.FirstOrDefault(i => i.ObjectType == ObjectType.User && i.ObjectId == userId);
if (image == null)
if (image is null)
{
throw new NotFoundException("Image not found");
}
Expand All @@ -130,23 +130,23 @@ public void DeleteImageById(int id)

public void DeleteImageRelatedToEvent(int id, string slug)
{
var @event = context.Events.FirstOrDefault(r => r.Slug == slug);
if (@event is null)
var relatedEvent = context.Events.FirstOrDefault(r => r.Slug == slug);
if (relatedEvent is null)
{
throw new NotFoundException("Event not found");
}

if (@event.Id != id)
{
throw new NotFoundException("Image is not related with this event");
}

var image = context.Images.FirstOrDefault(r => r.Id == id);
if (image is null)
{
throw new NotFoundException("Image not found");
}

if (image.ObjectId != relatedEvent.Id || image.ObjectType != ObjectType.Event)
{
throw new NotFoundException("This image is not related with this event");
}

context.Images.Remove(image);
context.SaveChanges();
}
Expand Down
7 changes: 6 additions & 1 deletion Server/ReasnAPI/ReasnAPI/Services/TagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public TagDto UpdateTag(int tagId, TagDto tagDto)

public void AddTagsFromList(List<Tag> tagsToAdd)
{
if (tagsToAdd is null)
{
throw new ArgumentException("No tag provided");
}

var existingTagsInDb = context.Tags
.Where(tag => tagsToAdd.Any(newTag => newTag.Name == tag.Name))
.ToList();
Expand All @@ -56,7 +61,7 @@ public void DeleteTag(int tagId)
{
var tag = context.Tags.FirstOrDefault(r => r.Id == tagId);

if (tag == null)
if (tag is null)
{
throw new NotFoundException("Tag not found");
}
Expand Down

0 comments on commit 9bb1ca6

Please sign in to comment.