/// <summary> /// Accept a friendship request sent to an user by another one. /// </summary> /// <param name="sender">The user that sends the request.</param> /// <param name="reciver">The user that receives the request and optionaly accept it.</param> public void AcceptRequest(User sender, User reciver) { ContractUtil.NotNull(sender); ContractUtil.NotNull(reciver); var requestRepository = _unitOfWork.FriendshipRequests; var request = requestRepository.FindSentFrom(sender).FirstOrDefault(friendshipRequest => reciver.Id.Equals(friendshipRequest.Reciver.Id)); // Checking that the request is already sent. if (Equals(request, null)) { throw new InvalidOperationException(); } var notificationRepository = _unitOfWork.Notifications; var userRepository = _unitOfWork.Users; var senderInContext = userRepository.FindById(sender.Id); // NOTE: Rethink and Analize that var reciverInContext = userRepository.FindById(reciver.Id); var newNotification = _notificationFactory.CreateFriendshipAccepted(sender, reciver); senderInContext.AddFriend(reciverInContext); reciverInContext.AddFriend(senderInContext); notificationRepository.Add(newNotification); request.State = FriendshipRequestState.Accepted; _unitOfWork.Commit(); }