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(); } }
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()); }
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(); }
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"); }