示例#1
0
        public async Task UnfollowUsers(Guid loggedUserId, IList <Guid> userIds)
        {
            // 1. lista curenta following
            var unfollowingList = await _followRepository.GetFollowingByFollower(loggedUserId);

            var unfollowingIdsList = unfollowingList.Select(f => f.IdUserFollowed).ToList();

            // 2.validare ids exista in tabelul de follow si tabelul de users
            var existingUsers = await _userRepository.GetAll();

            var existingUsersIds = existingUsers.Select(u => u.Id).ToList();

            var uniquesUsersIds = userIds
                                  .Where(i => unfollowingIdsList.Contains(i) && existingUsersIds.Contains(i))
                                  .ToList()
                                  .Distinct();

            // 3. delete from db : tble follow
            foreach (var id in uniquesUsersIds)
            {
                var newFollowEntity = new Follow(loggedUserId, id);
                _followRepository.Delete(newFollowEntity);
                await _followRepository.SaveChanges();
            }
        }
示例#2
0
 public int Delete(string deletelist)
 {
     string[] list = deletelist.TrimEnd(',').Split(',');
     foreach (var item in list)
     {
         Repository.Delete(Repository.Get(int.Parse(item)));
     }
     return(Repository.Save());
 }
示例#3
0
        public async Task UnFollow(Guid UserId)
        {
            var currentUser = _currentUserProvider.GetUserId;
            var model       = await this._followRepository.Get(currentUser, UserId);

            if (model == null)
            {
                throw new Exception("Cant find follow user");
            }
            await _followRepository.Delete(model);

            await this._currentUserProvider.ReloadFollowing();
        }
示例#4
0
        public string AddOrDeleteFollow(int id)
        {
            var myUser = _userRepository.Where(p => p.Username == HttpContext.Current.User.Identity.Name).Single();

            if (myUser.Follower.Any(p => p.followingId == id))
            {
                var follow = myUser.Follower.FirstOrDefault(p => p.followingId == id);
                _followRepository.Delete(follow);
                return("follow");
            }
            _followRepository.Add(new Follow {
                followingId = id, followerId = myUser.Id
            });
            return("Unfollow");
        }