public IActionResult PostRequestFriend(FriendRequest friendRequest, string id) { string userId; try { userId = User.Claims.First(c => c.Type == "UserID").Value; } catch { return(Unauthorized()); } var currentFriendRequest = _friendRequestService.GetSingleByCondition(s => s.Sender.Id == userId && s.Receiver.Id == id && s.IsCanceled != true && s.IsAccepted != true, null); if (currentFriendRequest != null) { return(BadRequest(new { message = "You have already sent request to this person!" })); } var sender = _userService.GetSingleByCondition(s => s.Id == userId, null); var receiver = _userService.GetSingleByCondition(s => s.Id == id, null); friendRequest.CreateDate = DateTime.Now; friendRequest.Sender = sender; friendRequest.Receiver = receiver; _friendRequestService.Add(friendRequest); _friendRequestService.SaveChanges(); return(Ok()); }