public void ExecuteMoveUserToGroup(string userScreenName, string targetGroupName) { // Find current group for screenName var groupModel = GroupModelList .FirstOrDefault(x => x.UserModelList.Any(y => y.ScreenName == userScreenName)); if (groupModel != null) { // Remove user from user list and update GroupScreenNamelList var userModel = groupModel.UserModelList.First(x => x.ScreenName == userScreenName); groupModel.UserModelList.Remove(userModel); groupModel.GroupScreenNamelList.RemoveAll(x => x == userScreenName); // Add user to target group and update GroupScreenNamelList groupModel = GroupModelList.First(x => x.GroupName == targetGroupName); groupModel.UserModelList.Add(userModel); userModel.GroupModel = groupModel; groupModel.GroupScreenNamelList.Add(userScreenName); // Update AvailableMoveToGroupList and rebind group model list var groupModelList = GroupModelList.ToList(); UpdateAvailableMoveToGroupList(userModel, groupModelList); // Save groups every time a move occurs SaveGroupsToFile(groupModelList); // Update UI GroupModelList = groupModelList; } }
private void ExecuteRefreshCommand() { if (_loginUser != null) { var groupModelList = GroupModelList.ToList(); groupModelList.ForEach(x => x.UserModelList.Clear()); RefreshFriends(groupModelList); } }
private void ExecuteGenerateGroupsCommand() { if (_loginUser != null) { var predefinedGroupNames = new string[] { "Tech", "Entertainment", "News" }; bool insertedGroup = false; var groupModelList = GroupModelList.ToList(); foreach (var groupName in predefinedGroupNames) { if (!groupModelList.Any(x => x.GroupName == groupName)) { int insertAtIndex = groupModelList.Count - 1; groupModelList.Insert(insertAtIndex, new GroupModel(groupName, GetGroupImagePath(groupName))); insertedGroup = true; } } if (insertedGroup) { SaveGroupsToFile(groupModelList); GroupModelList = groupModelList; foreach (var groupModel in groupModelList) { foreach (var userModel in groupModel.UserModelList) { UpdateAvailableMoveToGroupList(userModel, groupModelList); } } } GenerateGroupsCommandNotExecuted = false; OnPropertyChanged(nameof(GenerateGroupsCommandNotExecuted)); } }