public void AddFriend(User user) { if (user == null) { throw new Exception("Can not add non existing user to Friend's"); } if (UserFriends.Contains(user)) { throw new Exception($"User {user.Name} with id {user.Id} is alredy on Fiends list"); } UserFriends.Add(user); }
public CreateGroupViewModel() { InitializeCommands(); foreach (var chatDTO in NetworkManager.Client.GetChats(NetworkManager.CurrentUser)) { foreach (var chatUserDTO in NetworkManager.Client.GetChatUsers(chatDTO)) { if (UserFriends.FirstOrDefault((u) => u.User.UserId == chatUserDTO.UserId) == null && chatUserDTO.UserId != NetworkManager.CurrentUser.UserId) { UserFriends.Add(new UserModel() { User = NetworkManager.Client.GetUser(chatUserDTO.UserId) }); } } } }
public void AddToFriends(User subscriber) { if (Id == subscriber.Id) { throw new Exception("You can not add to friend yourself"); } if (!Subscribers.Any(sub => sub.Subscriber.Id == subscriber.Id)) { throw new Exception("This user is not your subscriber"); } if (UserFriends.Any(friend => friend.Friend.Id == subscriber.Id)) { throw new Exception("This user already your friend"); } UserFriends.Add(new UserFriend(Id, subscriber.Id)); RemoveFromSubscribers(subscriber.Id); }