Пример #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);
        }