Skip to content

Commit

Permalink
Added brackets to one line ifs, updated delete method in ObjectTypeSe…
Browse files Browse the repository at this point in the history
…rvice
  • Loading branch information
mkoper02 committed May 6, 2024
2 parents 1a58a27 + 34c24f4 commit 1c69f11
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
24 changes: 12 additions & 12 deletions Server/ReasnAPI/ReasnAPI/Services/AddressService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

Expand All @@ -10,9 +10,9 @@ public class AddressService(ReasnContext context)

public AddressDto? CreateAddress(AddressDto? addressDto)
{
if (addressDto is null)
if (addressDto is null)
{
return null;
return null;
}

var address = new Address
Expand All @@ -32,16 +32,16 @@ public class AddressService(ReasnContext context)

public AddressDto? UpdateAddress(int addressId, AddressDto? addressDto)
{
if (addressDto is null)
if (addressDto is null)
{
return null;
return null;
}

var address = _context.Addresses.FirstOrDefault(r => r.Id == addressId);

if (address is null)
if (address is null)
{
return null;
return null;
}

address.City = addressDto.City;
Expand All @@ -59,9 +59,9 @@ public bool DeleteAddress(int addressId)
{
var address = _context.Addresses.FirstOrDefault(r => r.Id == addressId);

if (address is null)
if (address is null)
{
return false ;
return false ;
}

_context.Addresses.Remove(address);
Expand All @@ -74,9 +74,9 @@ public bool DeleteAddress(int addressId)
{
var address = _context.Addresses.FirstOrDefault(r => r.Id == addressId);

if (address is null)
if (address is null)
{
return null;
return null;
}

return MapToAddressDto(address);
Expand Down Expand Up @@ -109,4 +109,4 @@ private static AddressDto MapToAddressDto(Address address)
};
}
}
}
}
14 changes: 7 additions & 7 deletions Server/ReasnAPI/ReasnAPI/Services/CommentService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

Expand All @@ -10,7 +10,7 @@ public class CommentService(ReasnContext context)

public CommentDto? CreateComment(CommentDto? commentDto)
{
if (commentDto is null)
if (commentDto is null)
{
return null;
}
Expand All @@ -31,14 +31,14 @@ public class CommentService(ReasnContext context)

public CommentDto? UpdateComment(int commentId, CommentDto? commentDto)
{
if (commentDto is null)
if (commentDto is null)
{
return null;
}

var comment = _context.Comments.FirstOrDefault(r => r.Id == commentId);

if (comment is null)
if (comment is null)
{
return null;
}
Expand All @@ -54,7 +54,7 @@ public bool DeleteComment(int commentId)
{
var comment = _context.Comments.FirstOrDefault(r => r.Id == commentId);

if (comment is null)
if (comment is null)
{
return false;
}
Expand All @@ -69,7 +69,7 @@ public bool DeleteComment(int commentId)
{
var comment = _context.Comments.FirstOrDefault(r => r.Id == commentId);

if (comment is null)
if (comment is null)
{
return null;
}
Expand Down Expand Up @@ -103,4 +103,4 @@ private static CommentDto MapToCommentDto(Comment comment)
};
}
}
}
}
18 changes: 9 additions & 9 deletions Server/ReasnAPI/ReasnAPI/Services/ObjectTypeService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Database;
using System.Linq.Expressions;

namespace ReasnAPI.Services
Expand All @@ -9,15 +9,15 @@ public class ObjectTypeService(ReasnContext context)

public ObjectType? CreateObjectType(ObjectType? objectType)
{
if (objectType is null)
if (objectType is null)
{
return null;
return null;
}

// check if object type with the same name already exists
var objectTypeDb = _context.ObjectTypes.FirstOrDefault(r => r.Name == objectType.Name);

if (objectTypeDb is not null)
if (objectTypeDb is not null)
{
return null;
}
Expand All @@ -30,14 +30,14 @@ public class ObjectTypeService(ReasnContext context)

public ObjectType? UpdateObjectType(ObjectType? objectType)
{
if (objectType is null)
if (objectType is null)
{
return null;
return null;
}

var objectTypeDb = _context.ObjectTypes.FirstOrDefault(r => r.Id == objectType.Id);

if (objectTypeDb is null)
if (objectTypeDb is null)
{
return null;
}
Expand All @@ -52,7 +52,7 @@ public bool DeleteObjectType(int objectTypeId)
{
var objectType = _context.ObjectTypes.FirstOrDefault(r => r.Id == objectTypeId);

if ( objectType is null)
if ( objectType is null)
{
return false;
}
Expand Down Expand Up @@ -80,4 +80,4 @@ public IEnumerable<ObjectType> GetAllObjectTypes()
return _context.ObjectTypes.AsEnumerable();
}
}
}
}
30 changes: 15 additions & 15 deletions Server/ReasnAPI/ReasnAPI/Services/ParticipantService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

Expand All @@ -10,17 +10,17 @@ public class ParticipantService(ReasnContext context)

public ParticipantDto? CreateParticipant(ParticipantDto? participantDto)
{
if (participantDto is null)
if (participantDto is null)
{
return null;
return null;
}

// check if participant already exists (same event and user)
var participantDb = _context.Participants.FirstOrDefault(r => r.Event.Id == participantDto.EventId && r.User.Id == participantDto.UserId);

if (participantDb is not null)
if (participantDb is not null)
{
return null;
return null;
}

var userInDb = _context.Users.FirstOrDefault(r => r.Id == participantDto.UserId);
Expand All @@ -29,7 +29,7 @@ public class ParticipantService(ReasnContext context)

if (userInDb is null || eventInDb is null || statusInDb is null)
{
return null;
return null;
}

var participant = new Participant
Expand All @@ -47,21 +47,21 @@ public class ParticipantService(ReasnContext context)

public ParticipantDto? UpdateParticipant(int participantId, ParticipantDto? participantDto)
{
if (participantDto is null)
if (participantDto is null)
{
return null;
return null;
}

var participant = _context.Participants.FirstOrDefault(r => r.Id == participantId);
if (participant is null)
if (participant is null)
{
return null;
return null;
}

var status = _context.Statuses.FirstOrDefault(r => r.Id == participantDto.StatusId);
if (status is null)
if (status is null)
{
return null;
return null;
}

participant.StatusId = participantDto.StatusId;
Expand All @@ -75,7 +75,7 @@ public bool DeleteParticipant(int participantId)
{
var participant = _context.Participants.FirstOrDefault(r => r.Id == participantId);

if (participant is null)
if (participant is null)
{
return false;
}
Expand All @@ -90,7 +90,7 @@ public bool DeleteParticipant(int participantId)
{
var participant = _context.Participants.FirstOrDefault(r => r.Id == participantId);

if (participant is null)
if (participant is null)
{
return null;
}
Expand Down Expand Up @@ -123,4 +123,4 @@ private static ParticipantDto MapToParticipantDto(Participant participant)
};
}
}
}
}
16 changes: 8 additions & 8 deletions Server/ReasnAPI/ReasnAPI/Services/RoleService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

Expand All @@ -10,15 +10,15 @@ public class RoleService(ReasnContext context)

public RoleDto? CreateRole(RoleDto? roleDto)
{
if (roleDto is null)
if (roleDto is null)
{
return null;
}

// check if role with the same name already exists
var roleDb = _context.Roles.FirstOrDefault(r => r.Name == roleDto.Name);

if (roleDb is not null)
if (roleDb is not null)
{
return null;
}
Expand All @@ -36,7 +36,7 @@ public class RoleService(ReasnContext context)

public RoleDto? UpdateRole(int roleId, RoleDto? roleDto)
{
if (roleDto is null)
if (roleDto is null)
{
return null;
}
Expand All @@ -45,7 +45,7 @@ public class RoleService(ReasnContext context)

if (role is null)
{
return null;
return null;
}

role.Name = roleDto.Name;
Expand All @@ -59,7 +59,7 @@ public bool DeleteRole(int roleId)
{
var role = _context.Roles.FirstOrDefault(r => r.Id == roleId);

if (role is null)
if (role is null)
{
return false;
}
Expand All @@ -76,7 +76,7 @@ public bool DeleteRole(int roleId)

if (role is null)
{
return null;
return null;
}

return MapToRoleDto(role);
Expand Down Expand Up @@ -105,4 +105,4 @@ private static RoleDto MapToRoleDto(Role role)
};
}
}
}
}
Loading

0 comments on commit 1c69f11

Please sign in to comment.