Exemple #1
0
        public async Task <bool> AddFriend(string userId, ClaimsPrincipal userClaims)
        {
            var requestUser = await _userManager.GetUserAsync(userClaims);

            if (requestUser == null)
            {
                return(false);
            }

            _profileRepo.LoadUserProfileWithFriendsAndDevices(requestUser);

            var userProfile = _profileRepo.GetProfileByExternalId(userId);

            if (userProfile == null)
            {
                return(false);
            }

            _profileRepo.LoadUserFromProfile(userProfile);

            if (userProfile.User == null)
            {
                return(false);
            }

            _profileRepo.LoadUserProfileWithFriendsAndDevices(userProfile.User);

            var existingReqeuest = ExistingRequest(userProfile.User, requestUser);

            if (existingReqeuest != null)
            {
                _friendRepo.AcceptFriendRequest(existingReqeuest);
            }
            else
            {
                _friendRepo.AddFriendRequest(requestUser, userProfile.User);
            }

            if (!_uow.Commit())
            {
                return(false);
            }

            if (existingReqeuest != null)
            {
                ApplyGeolocationToFriend(requestUser, userProfile.User);
            }

            return(true);
        }
        public void SendFriendRequest(Citizen proposer, Citizen other)
        {
            friendRepository.AddFriendRequest(proposer, other);

            using (NoSaveChanges)
            {
                string link = EntityLinkCreator.Create(proposer.Entity).ToHtmlString();

                warningService.AddWarning(other.ID, $"You received friendship request from {link}.");
                popupService.AddInfo($"You've sent friend request to {other.Entity.Name}.");
            }

            ConditionalSaveChanges(friendRepository);
        }