public async Task FollowUsers(Guid loggedUserId, IList <Guid> userIds) { //1. lista curenta users pe care ii urmarim var followingList = await _followRepository.GetFollowingByFollower(loggedUserId); var followingIdsList = followingList.Select(f => f.IdUserFollowed).ToList(); //2. user id exists var existingUsers = await _userRepository.GetAll(); var existingUsersIds = existingUsers.Select(u => u.Id).ToList(); //3. comparam id => ids unice var uniquesUsersIds = userIds .Where(i => !followingIdsList.Contains(i) && existingUsersIds.Contains(i)) .ToList() .Distinct(); //4. add to db foreach (var id in uniquesUsersIds) { var newFollowEntity = new Follow(loggedUserId, id); await _followRepository.Add(newFollowEntity); await _followRepository.SaveChanges(); } //await _followRepository.AddRange(uniquesUsersIds.Select(i => new Follow(loggedUserId, i)).ToList()); }
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"); }
public async Task Follow(Guid UserId) { var currentUser = _currentUserProvider.GetUserId; var model = new FollowModel(new FollowEntity { UserId = _currentUserProvider.GetUserId, FollowUserId = UserId, Id = Guid.NewGuid() } ); await _followRepository.Add(model); await this._currentUserProvider.ReloadFollowing(); }
public int Add(ViewFollow model) { Repository.Add(ViewFollow.ToEntity(model)); return(Repository.Save()); }
public Follow AddFollows(Follow follow) { return(_followRepository.Add(follow)); }