public async Task <MessageModel> SendMessage(SendMessageRequest request, string SourceId) { var targetUser = await _userService.Get(SourceId, request.TargetId); if (targetUser != null && (targetUser.OpenChat || await _friendService.AreUsersFriends(SourceId, request.TargetId))) { return(await _chatRepository.SendMessage(request, SourceId)); } throw new ChatPermissionException("Cannot send message to user"); }