School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,44 @@
<UserControl x:Class="District_3_App.Settings_Privacy_GUI.MantainGroups"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:District_3_App.Settings_Privacy_GUI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="White">
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<Label FontSize="25" Content="Mantain your groups" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top"/>
<ListView x:Name="allGroupsListView" d:ItemsSource="{d:SampleData ItemCount=5}" Margin="10,84,508,94">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<ListView SelectionChanged="CurrentUserGroupsListView_SelectionChanged" x:Name="currentUserGroupsListView" d:ItemsSource="{d:SampleData ItemCount=5}" Margin="384,84,258,217">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<ListView x:Name="currentUserGroupMembersListView" d:ItemsSource="{d:SampleData ItemCount=5}" Margin="558,84,82,217">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
<Label FontSize="18" Content="All available groups:" HorizontalAlignment="Left" Margin="10,48,0,0" VerticalAlignment="Top"/>
<Label FontSize="18" Content="Groups you are in:" HorizontalAlignment="Left" Margin="384,53,0,0" VerticalAlignment="Top"/>
<Label FontSize="18" Content="Members: " HorizontalAlignment="Left" Margin="558,53,0,0" VerticalAlignment="Top" Height="29"/>
<Label FontWeight="Bold" VerticalAlignment="Bottom" Content="Search for a group:" Margin="10,0,508,68"></Label>
<TextBox TextChanged="SearchGroupNameTextBox_TextChanged" x:Name="searchGroupNameTextBox" FontSize="18" HorizontalAlignment="Left" Margin="11,367,0,0" TextWrapping="Wrap" Text="search group by name..." VerticalAlignment="Top" Width="227"/>
<Button Click="JoinGroupButton_Click" Background="White" x:Name="joinGroupButton" FontSize="16" Content="Join" HorizontalAlignment="Left" Margin="240,84,0,0" VerticalAlignment="Top"/>
<Button Click="CreateGroupButton_Click" x:Name="createGroupButton" FontSize="16" Background="White" Content="Create new group" HorizontalAlignment="Left" Margin="390,311,0,0" VerticalAlignment="Top" Width="140"/>
<Button Click="AddMemberToSpecificGroupButton_Click" x:Name="addMemberToSpecificGroupButton" Background="White" Content="Add member" HorizontalAlignment="Left" Margin="571,213,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="addMemberToSelectedGroupTextBox" HorizontalAlignment="Left" Margin="558,233,0,0" TextWrapping="Wrap" Text="give username..." VerticalAlignment="Top" Width="100"/>
<TextBox Padding="3" x:Name="newGroupNameTextBox" HorizontalAlignment="Left" Margin="382,349,0,0" TextWrapping="Wrap" Text="give a name to the group..." VerticalAlignment="Top" Width="157" Height="31"/>
</Grid>
</UserControl>
@@ -0,0 +1,202 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
using District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Service;
namespace District_3_App.Settings_Privacy_GUI
{
/// <summary>
/// Interaction logic for MantainGroups.xaml
/// </summary>
public partial class MantainGroups : UserControl
{
private ProfileNetworkInfoService profileNetworkInfoService;
private User currentConnectedUser;
public MantainGroups(User currentConnectedUser, ProfileNetworkInfoService profileNetworkInfoService)
{
InitializeComponent();
this.currentConnectedUser = currentConnectedUser;
this.profileNetworkInfoService = profileNetworkInfoService;
// PopulateAllGroupsList();
PopulateGroupsForCurrentUser();
PopulateGroupMemberForSelectedGroup();
}
public void PopulateAllGroupsList()
{
if (searchGroupNameTextBox.Text != string.Empty && profileNetworkInfoService != null)
{
allGroupsListView.Items.Clear();
foreach (var group in profileNetworkInfoService.GetAllGroupsService())
{
if (group.GroupName.Contains(searchGroupNameTextBox.Text) || searchGroupNameTextBox.Text == string.Empty)
{
allGroupsListView.Items.Add(group.GroupName);
}
}
}
else if (searchGroupNameTextBox.Text == string.Empty)
{
allGroupsListView.Items.Clear();
foreach (var group in profileNetworkInfoService.GetAllGroupsService())
{
allGroupsListView.Items.Add(group.GroupName);
}
}
}
public void PopulateGroupsForCurrentUser()
{
currentUserGroupsListView.Items.Clear();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
foreach (var group in profile.Groups)
{
currentUserGroupsListView.Items.Add(group.GroupName);
}
}
public void PopulateGroupMemberForSelectedGroup()
{
if (currentUserGroupsListView.SelectedItems.Count > 0)
{
currentUserGroupMembersListView.Items.Clear();
string selectedGroupName = currentUserGroupsListView.SelectedItem.ToString(); // get selected group members
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
foreach (var group in profile.Groups)
{
if (group.GroupName == selectedGroupName)
{
foreach (var groupMember in group.GroupMembers)
{
currentUserGroupMembersListView.Items.Add(groupMember.Username);
}
}
}
}
}
private void CurrentUserGroupsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PopulateGroupMemberForSelectedGroup();
}
private void SearchGroupNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
PopulateAllGroupsList();
}
private void JoinGroupButton_Click(object sender, RoutedEventArgs e)
{
if (allGroupsListView.SelectedItems.Count > 0)
{
bool userAlreadyInGroup = false;
string selectedGroupName = allGroupsListView.SelectedItem.ToString();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
foreach (var groupMember in profileNetworkInfoService.GetGroupByName(selectedGroupName).GroupMembers)
{
if (groupMember.Username == profile.User.Username)
{
userAlreadyInGroup = true;
}
}
if (userAlreadyInGroup == false)
{
profileNetworkInfoService.AddGroupToCurrentUser(profile, profileNetworkInfoService.GetGroupByName(selectedGroupName));
profileNetworkInfoService.GetGroupByName(selectedGroupName).GroupMembers.Add(profile.User);
profileNetworkInfoService.SaveDataIntoXML();
PopulateGroupsForCurrentUser();
PopulateGroupMemberForSelectedGroup();
}
}
}
private void CreateGroupButton_Click(object sender, RoutedEventArgs e)
{
if (newGroupNameTextBox.Text != string.Empty)
{
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
bool alreadyExists = false;
foreach (var group in profileNetworkInfoService.GetAllGroupsService())
{
if (group.GroupName == newGroupNameTextBox.Text)
{
alreadyExists = true;
}
}
if (alreadyExists)
{
MessageBox.Show("Group with this name already exists", "Error creating new group");
}
else
{
List<User> groupMembers = new List<User>();
groupMembers.Add(currentConnectedUser);
profileNetworkInfoService.CreateGroupToRepository(newGroupNameTextBox.Text, groupMembers);
profile.Groups.Add(profileNetworkInfoService.GetGroupByName(newGroupNameTextBox.Text));
profileNetworkInfoService.SaveDataIntoXML();
PopulateAllGroupsList();
PopulateGroupsForCurrentUser();
PopulateGroupMemberForSelectedGroup();
}
}
}
private void AddMemberToSpecificGroupButton_Click(object sender, RoutedEventArgs e)
{
if (addMemberToSelectedGroupTextBox.Text != string.Empty && currentUserGroupsListView.SelectedItems.Count > 0)
{
string selectedGroup = currentUserGroupsListView.SelectedItem.ToString();
if (profileNetworkInfoService.GetUserByName(addMemberToSelectedGroupTextBox.Text) != null && profileNetworkInfoService.GetGroupByName(selectedGroup) != null)
{
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
if (profileNetworkInfoService.AddMemberToGroup(selectedGroup, profileNetworkInfoService.GetUserByName(addMemberToSelectedGroupTextBox.Text)))
{
UserProfileSocialNetworkInfo addedMemberProfile = profileNetworkInfoService.GetProfileSocialNetworkInfoByUser(addMemberToSelectedGroupTextBox.Text);
if (addedMemberProfile != null)
{
addedMemberProfile.Groups.Add(profileNetworkInfoService.GetGroupByName(selectedGroup));
profileNetworkInfoService.AddMemberToGroupProfile(profile, selectedGroup, addMemberToSelectedGroupTextBox.Text);
profileNetworkInfoService.SaveDataIntoXML();
PopulateGroupMemberForSelectedGroup();
PopulateGroupsForCurrentUser();
}
else
{
MessageBox.Show("Profile of give user not found, try again", "error");
}
}
}
}
}
}
}
@@ -0,0 +1,236 @@
<UserControl x:Class="District_3_App.Settings_Privacy_GUI.SettingsPrivacy_UserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:District_3_App.Settings_Privacy_GUI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="White">
<Grid x:Name="settingsPrivacyGrid" HorizontalAlignment="Left">
<ListView x:Name="restrictedPostsAudienceListView"
HorizontalAlignment="Left"
Height="39"
Margin="20,238,0,0"
VerticalAlignment="Top"
Width="200"
d:ItemsSource="{d:SampleData ItemCount=5}"
BorderThickness="0">
<!-- Define a style for ListViewItem to change the selected item color -->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{TemplateBinding Background}">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Trigger to change the background color of the selected item -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="LightBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<!-- You can define columns here -->
<GridViewColumn Header="Column Header" Width="Auto"/>
</GridView>
</ListView.View>
<!-- Remove any border on the ListView -->
<ListView.Template>
<ControlTemplate TargetType="ListView">
<Border BorderThickness="0">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ListView.Template>
</ListView>
<Label Content="Restricted Posts Audience:" FontSize="10" HorizontalAlignment="Left" Margin="20,202,0,0" VerticalAlignment="Top"/>
<Label Content="Groups:" FontSize="10" HorizontalAlignment="Left" Margin="20,353,0,0" VerticalAlignment="Top" Height="23" Width="63"/>
<Label Content="Restricted Stories Audience:" FontSize="10" HorizontalAlignment="Left" Margin="20,131,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Height="23" Width="133">
<Label.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-0.316"/>
<TranslateTransform/>
</TransformGroup>
</Label.RenderTransform>
</Label>
<ListView x:Name="restrictedStoriesAudienceListView"
HorizontalAlignment="Left"
Height="39"
Margin="20,158,0,0"
VerticalAlignment="Top"
Width="200"
d:ItemsSource="{d:SampleData ItemCount=5}"
BorderThickness="0">
<!-- Define a style for ListViewItem to change the selected item color -->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{TemplateBinding Background}">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Trigger to change the background color of the selected item -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="LightBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<!-- You can define columns here -->
<GridViewColumn Header="Column Header" Width="Auto"/>
</GridView>
</ListView.View>
<!-- Remove any border on the ListView -->
<ListView.Template>
<ControlTemplate TargetType="ListView">
<Border BorderThickness="0">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ListView.Template>
</ListView>
<ListView x:Name="groupsListView"
HorizontalAlignment="Left"
Height="39"
Margin="20,381,0,0"
VerticalAlignment="Top"
Width="200"
d:ItemsSource="{d:SampleData ItemCount=5}"
BorderThickness="0">
<!-- Define a style for ListViewItem to change the selected item color -->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{TemplateBinding Background}">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Trigger to change the background color of the selected item -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="LightBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<!-- You can define columns here -->
<GridViewColumn Header="Column Header" Width="Auto"/>
</GridView>
</ListView.View>
<!-- Remove any border on the ListView -->
<ListView.Template>
<ControlTemplate TargetType="ListView">
<Border BorderThickness="0">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ListView.Template>
</ListView>
<Label Content="Settings &amp; Privacy" FontSize="15" HorizontalAlignment="Left" VerticalAlignment="Top" Height="28" Width="152" Margin="20,48,0,0"/>
<Label Content="Password:" FontSize="10" HorizontalAlignment="Left" Margin="20,90,0,0" VerticalAlignment="Top" Width="63" Height="26"/>
<Label Content="Blocked Accounts:" FontSize="10" HorizontalAlignment="Left" Margin="20,282,0,0" VerticalAlignment="Top" Height="22" Width="109"/>
<CheckBox HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="10" x:Name="IsProfilePrivateCheckBox" Content="Private Account" Margin="80,425,0,0" Unchecked="IsProfilePrivateCheckBox_Unchecked" Checked="IsProfilePrivateCheckBox_Checked"/>
<Button Content="Add" FontSize="11" x:Name="AddRestrictedStoriesUserButton" HorizontalAlignment="Left" Margin="248,134,0,0" VerticalAlignment="Top" Background="White" Click="AddRestrictedStoriesUserButton_Click"/>
<Button Content="Add" FontSize="11" x:Name="AddRestrictedPostsUserButton" HorizontalAlignment="Left" Margin="248,204,0,0" VerticalAlignment="Top" Background="White" RenderTransformOrigin="0.565,0.537" Click="AddRestrictedPostsUserButton_Click"/>
<Button Content="Add" FontSize="11" x:Name="AddBlockedAccountButton" HorizontalAlignment="Left" Margin="248,284,0,0" VerticalAlignment="Top" Background="White" Click="AddBlockedAccountButton_Click"/>
<Button Click="MantainGroupsButton_Click" Content="Edit" FontSize="11" x:Name="mantainGroupsButton" HorizontalAlignment="Left" Margin="248,355,0,0" VerticalAlignment="Top" Background="White" RenderTransformOrigin="0.392,1.181"/>
<Button Content="Remove" FontSize="11" x:Name="RemoveRestrictedStoriesUserButton" HorizontalAlignment="Left" Margin="291,134,0,0" VerticalAlignment="Top" Background="White" Click="RemoveRestrictedStoriesUserButton_Click"/>
<Button Content="Remove" FontSize="11" x:Name="RemoveRestrictedPostsUserButton" HorizontalAlignment="Left" Margin="291,204,0,0" VerticalAlignment="Top" Background="White" RenderTransformOrigin="0.565,0.537" Click="RemoveRestrictedPostsUserButton_Click"/>
<Button Content="Remove" FontSize="11" x:Name="RemoveBlockedAccountButton" HorizontalAlignment="Left" Margin="291,284,0,0" VerticalAlignment="Top" Background="White" Click="RemoveBlockedAccountButton_Click"/>
<Button Click="LeaveGroupButton_Click" Content="Leave" FontSize="11" x:Name="LeaveGroupButton" HorizontalAlignment="Left" Margin="291,355,0,0" VerticalAlignment="Top" Background="White" RenderTransformOrigin="0.565,0.537"/>
<ListView x:Name="blockedProfilesListView" HorizontalAlignment="Left"
Height="39"
Margin="20,309,0,0"
VerticalAlignment="Top"
Width="200"
d:ItemsSource="{d:SampleData ItemCount=5}"
BorderThickness="0">
<!-- Define a style for ListViewItem to change the selected item color -->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{TemplateBinding Background}">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Trigger to change the background color of the selected item -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="LightBlue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<!-- You can define columns here -->
<GridViewColumn Header="Column Header" Width="Auto"/>
</GridView>
</ListView.View>
<!-- Remove any border on the ListView -->
<ListView.Template>
<ControlTemplate TargetType="ListView">
<Border BorderThickness="0">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ListView.Template>
</ListView>
<TextBox x:Name="usernameToBlockTextBox" HorizontalAlignment="Left" Margin="349,284,0,0" TextWrapping="Wrap" Text="Block some user..." VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="usernameRestrictTextBox" HorizontalAlignment="Left" Margin="349,158,0,0" TextWrapping="Wrap" Text="give username..." VerticalAlignment="Top" Width="120"/>
<Label Content="Username to restrict:" HorizontalAlignment="Left" Margin="349,125,0,0" VerticalAlignment="Top" Width="120"/>
<PasswordBox x:Name="passwordChangeTextBox" HorizontalAlignment="Left" Margin="186,94,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Change password" Background="White" HorizontalAlignment="Left" Margin="323,94,0,0" VerticalAlignment="Top" Height="18" Width="102" Click="ChangePasswordButton_Click"/>
</Grid>
</UserControl>
@@ -0,0 +1,405 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
using District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Service;
namespace District_3_App.Settings_Privacy_GUI
{
/// <summary>
/// Interaction logic for SettingsPrivacy_UserControl.xaml
/// </summary>
public partial class SettingsPrivacy_UserControl : UserControl
{
private User currentConnectedUser;
private ProfileNetworkInfoService profileNetworkInfoService;
public bool IsProfilePrivate { get; set; }
public SettingsPrivacy_UserControl(User currentConnectedUser, ProfileNetworkInfoService profileNetworkInfoService)
{
InitializeComponent();
this.currentConnectedUser = currentConnectedUser;
this.profileNetworkInfoService = profileNetworkInfoService;
PopulateGroupsForCurrentUser();
PopulateRestrictedPostsAudienceForCurrentUser();
PopulateRestrictedStoriesAudienceForCurrentUser();
PopulateBlockedAccountsForCurrentUser();
this.passwordChangeTextBox.Password = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser).User.Password;
// this.profileNetworkInfoService = profileNetworkInfoService;
}
public void PopulateBlockedAccountsForCurrentUser()
{
blockedProfilesListView.Items.Clear();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
foreach (var blockedProfile in profile.BlockedProfiles)
{
blockedProfilesListView.Items.Add(blockedProfile.User.Username);
}
}
public void PopulateRestrictedPostsAudienceForCurrentUser()
{
restrictedPostsAudienceListView.Items.Clear();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
foreach (var restrictedUser in profile.RestrictedPostsAudience)
{
restrictedPostsAudienceListView.Items.Add(restrictedUser.Username);
}
}
public void PopulateRestrictedStoriesAudienceForCurrentUser()
{
restrictedStoriesAudienceListView.Items.Clear();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
foreach (var restrictedUser in profile.RestrictedStoriesAudience)
{
restrictedStoriesAudienceListView.Items.Add(restrictedUser.Username);
}
}
public void PopulateGroupsForCurrentUser()
{
groupsListView.Items.Clear();
// all groups for current user
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
// all the groups
// List<Group> groupsRepo = profileNetworkInfoService.GetAllGroupsService();
foreach (var group in profile.Groups)
{
groupsListView.Items.Add(group.GroupName);
// foreach (var groupMember in group.groupMembers)
// {
// groupMembersListView.Items.Add(groupMember.username);
// }
}
}
private void LeaveGroupButton_Click(object sender, RoutedEventArgs e)
{
string selectedGroupName = groupsListView.SelectedItem.ToString();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
profileNetworkInfoService.RemoveGroupFromCurrentUser(profile, profileNetworkInfoService.GetGroupByName(selectedGroupName));
profileNetworkInfoService.SaveDataIntoXML();
groupsListView.Items.Clear(); // reset the list view
foreach (var gr in profile.Groups)
{
groupsListView.Items.Add(gr.GroupName);
// foreach (var groupMember in group.groupMembers)
// {
// groupMembersListView.Items.Add(groupMember.username);
// }
}
// testSelectedItem.Text = selectedGroupName;
}
private void MantainGroupsButton_Click(object sender, RoutedEventArgs e)
{
MantainGroups mantainGroupsUserControl = new MantainGroups(currentConnectedUser, profileNetworkInfoService);
settingsPrivacyGrid.Children.Clear();
settingsPrivacyGrid.Children.Add(mantainGroupsUserControl);
}
private void RemoveBlockedAccountButton_Click(object sender, RoutedEventArgs e)
{
string selectedBlockedUsername = blockedProfilesListView.SelectedItem.ToString();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
profileNetworkInfoService.RemoveBlockedProfileFromCurrentUser(profile, profileNetworkInfoService.GetBlockedProfileByName(profile, selectedBlockedUsername));
profileNetworkInfoService.SaveDataIntoXML();
blockedProfilesListView.Items.Clear(); // reset the list view
foreach (var blockedProfile in profile.BlockedProfiles)
{
blockedProfilesListView.Items.Add(blockedProfile.User.Username);
// foreach (var groupMember in group.groupMembers)
// {
// groupMembersListView.Items.Add(groupMember.username);
// }
}
}
private void AddBlockedAccountButton_Click(object sender, RoutedEventArgs e)
{
if (usernameToBlockTextBox.Text != string.Empty)
{
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
bool usernameExists = false;
foreach (var user in profileNetworkInfoService.GetAllUsers())
{
if (user.Username == usernameToBlockTextBox.Text)
{
usernameExists = true;
}
}
if (!usernameExists)
{
MessageBox.Show("Error: user with such username does not exist");
}
else
{
bool alreadyExists = false;
foreach (var blockedProfile in profile.BlockedProfiles)
{
if (blockedProfile.User.Username == usernameToBlockTextBox.Text)
{
alreadyExists = true;
}
}
if (alreadyExists)
{
MessageBox.Show("User is already blocked by you", "Error");
}
else
{
DateTime newDate = DateTime.Now;
BlockedProfile profileToBlock = new BlockedProfile(profileNetworkInfoService.GetUserByName(usernameToBlockTextBox.Text), newDate);
profile.BlockedProfiles.Add(profileToBlock);
profileNetworkInfoService.SaveDataIntoXML();
}
blockedProfilesListView.Items.Clear();
foreach (var blockedProfile in profile.BlockedProfiles)
{
blockedProfilesListView.Items.Add(blockedProfile.User.Username);
}
}
}
}
private void AddRestrictedStoriesUserButton_Click(object sender, RoutedEventArgs e)
{
if (usernameRestrictTextBox.Text != string.Empty)
{
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
bool usernameExists = false;
foreach (var user in profileNetworkInfoService.GetAllUsers())
{
if (user.Username == usernameRestrictTextBox.Text)
{
usernameExists = true;
}
}
if (!usernameExists)
{
MessageBox.Show("Error: user with such username does not exist");
}
else
{
bool alreadyExists = false;
foreach (var user in profile.RestrictedStoriesAudience)
{
if (user.Username == usernameRestrictTextBox.Text)
{
alreadyExists = true;
}
}
if (alreadyExists)
{
MessageBox.Show("User is already restricted from seeing your stories", "Error");
}
else
{
profile.RestrictedStoriesAudience.Add(profileNetworkInfoService.GetUserByName(usernameRestrictTextBox.Text));
profileNetworkInfoService.SaveDataIntoXML();
}
restrictedStoriesAudienceListView.Items.Clear();
foreach (var restrictedUser in profile.RestrictedStoriesAudience)
{
restrictedStoriesAudienceListView.Items.Add(restrictedUser.Username);
}
}
}
}
private void AddRestrictedPostsUserButton_Click(object sender, RoutedEventArgs e)
{
if (usernameRestrictTextBox.Text != string.Empty)
{
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
bool usernameExists = false;
foreach (var user in profileNetworkInfoService.GetAllUsers())
{
if (user.Username == usernameRestrictTextBox.Text)
{
usernameExists = true;
}
}
if (!usernameExists)
{
MessageBox.Show("Error: user with such username does not exist");
}
else
{
bool alreadyExists = false;
foreach (var user in profile.RestrictedPostsAudience)
{
if (user.Username == usernameRestrictTextBox.Text)
{
alreadyExists = true;
}
}
if (alreadyExists)
{
MessageBox.Show("User is already restricted from seeing your stories", "Error");
}
else
{
profile.RestrictedPostsAudience.Add(profileNetworkInfoService.GetUserByName(usernameRestrictTextBox.Text));
profileNetworkInfoService.SaveDataIntoXML();
}
restrictedPostsAudienceListView.Items.Clear();
foreach (var restrictedUser in profile.RestrictedPostsAudience)
{
restrictedPostsAudienceListView.Items.Add(restrictedUser.Username);
}
}
}
}
private void RemoveRestrictedStoriesUserButton_Click(object sender, RoutedEventArgs e)
{
try
{
string selectedUsername = restrictedStoriesAudienceListView.SelectedItem.ToString();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
profileNetworkInfoService.RemoveRestrictedStoriesAudienceUserFromCurrentUser(profile, profileNetworkInfoService.GetUserByName(selectedUsername));
profileNetworkInfoService.SaveDataIntoXML();
restrictedStoriesAudienceListView.Items.Clear(); // reset the list view
foreach (var restrictedUser in profile.RestrictedStoriesAudience)
{
restrictedStoriesAudienceListView.Items.Add(restrictedUser.Username);
// foreach (var groupMember in group.groupMembers)
// {
// groupMembersListView.Items.Add(groupMember.username);
// }
}
}
catch (Exception ex)
{
MessageBox.Show($"[{ex.Message}]: No user selected to remove", "Error");
}
}
private void RemoveRestrictedPostsUserButton_Click(object sender, RoutedEventArgs e)
{
try
{
string selectedUsername = restrictedPostsAudienceListView.SelectedItem.ToString();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
profileNetworkInfoService.RemoveRestrictedPostsAudienceUserFromCurrentUser(profile, profileNetworkInfoService.GetUserByName(selectedUsername));
profileNetworkInfoService.SaveDataIntoXML();
restrictedPostsAudienceListView.Items.Clear(); // reset the list view
foreach (var restrictedUser in profile.RestrictedPostsAudience)
{
restrictedPostsAudienceListView.Items.Add(restrictedUser.Username);
// foreach (var groupMember in group.groupMembers)
// {
// groupMembersListView.Items.Add(groupMember.username);
// }
}
}
catch (Exception ex)
{
MessageBox.Show($"[{ex.Message}]: No user selected to remove", "Error");
}
}
private void ChangePasswordButton_Click(object sender, RoutedEventArgs e)
{
string newPassword = passwordChangeTextBox.Password;
if (newPassword.Length < 15)
{
MessageBox.Show("The new password should contian at least 15 digits", "Error");
return;
}
bool containsSpecialCharacter = false;
bool containsDigit = false;
foreach (char c in newPassword)
{
if (char.IsDigit(c))
{
containsDigit = true;
}
else if (char.IsSymbol(c) || char.IsPunctuation(c))
{
containsSpecialCharacter = true;
}
}
if (!containsSpecialCharacter || !containsDigit)
{
MessageBox.Show("The new password must contain at least one digit and one special character", "Error");
return;
}
// set new password for the current connected user
this.currentConnectedUser.Password = newPassword;
profileNetworkInfoService.SaveDataIntoXML();
}
private void IsProfilePrivateCheckBox_Checked(object sender, RoutedEventArgs e)
{
profileNetworkInfoService.SwitchAccountPrivacyPublicPrivate(currentConnectedUser);
}
private void IsProfilePrivateCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
profileNetworkInfoService.SwitchAccountPrivacyPublicPrivate(currentConnectedUser);
}
}
}