Example #1
0
        public void AcceptFriendRequest(AddFriendDto addFriend)
        {
            var existingFriendship = _friendsRepository.GetFirstWhere(x => x.UserId == addFriend.UserId && x.FriendId == addFriend.FriendId);

            if (existingFriendship != null)
            {
                throw new FlowException("Already friends!");
            }

            var newFriend = new Friends()
            {
                UserId   = addFriend.UserId,
                FriendId = addFriend.FriendId
            };

            var newFriendTwo = new Friends()
            {
                UserId   = addFriend.FriendId,
                FriendId = addFriend.UserId
            };

            _friendsRepository.Add(newFriend);
            _friendsRepository.Add(newFriendTwo);
            _friendsRepository.SaveEntities();
        }