public async Task ValidateFriendRequest(int userId) { if (userId == (int)_currentUserService.UserId) { throw new BadRequestException(); } var friendshipSpecification = new FriendshipFilterSpecification((int)_currentUserService.UserId, userId); var friendship = await _uow.Repository <Domain.Entities.Friendship>().FindOneAsync(friendshipSpecification); if (friendship != null) { if (friendship.StatusId == (int)FriendshipStatus.Accepted) { AddValidationError("Friendship", $"You are already friends!"); } else if (friendship.StatusId == (int)FriendshipStatus.Declined) { AddValidationError("Friendship", $"Friendship is already declined!"); } else if (friendship.StatusId == (int)FriendshipStatus.Sent) { AddValidationError("Friendship", $"Friendship request is already sent!"); } } ThrowValidationErrorsIfNotEmpty(); }
public async Task DeclineFriendRequest(int userId) { var friendshipSpecification = new FriendshipFilterSpecification((int)_currentUserService.UserId, userId); var friendship = await _uow.Repository <Domain.Entities.Friendship>().FindOneAsync(friendshipSpecification); friendship.StatusId = (int)FriendshipStatus.Declined; await _uow.SaveAsync(); }
public async Task ValidateAcceptOrDeclineFriendRequest(int userId) { var friendshipSpecification = new FriendshipFilterSpecification((int)_currentUserService.UserId, userId); var friendship = await _uow.Repository <Domain.Entities.Friendship>().FindOneAsync(friendshipSpecification); AddValidationErrorIfValueIsNull(friendship, "Friendship", $"Friendship doesnt't exist!"); ThrowValidationErrorsIfNotEmpty(); var loggedUserId = (int)_currentUserService.UserId; if (friendship.SenderId == loggedUserId || friendship.StatusId != (int)FriendshipStatus.Sent) { throw new BadRequestException(); } }
public async Task <RecordNameDto> GetFriendShipStatus(int userId) { var friendshipSpecification = new FriendshipFilterSpecification((int)_currentUserService.UserId, userId); var friendship = await _uow.Repository <Domain.Entities.Friendship>().FindOneAsync(friendshipSpecification); if (friendship == null) { return(new RecordNameDto { Id = 0, Name = "None" }); } return(new RecordNameDto { Id = friendship.StatusId, Name = Enum.GetName(typeof(FriendshipStatus), friendship.StatusId) }); }