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,24 @@
<UserControl x:Class="District_3_App.CloseFriends_GUI.CloseFriendsSection_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.CloseFriends_GUI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" Background="White">
<Grid HorizontalAlignment="Left">
<Label FontSize="25" Content="Close Friends" HorizontalAlignment="Left" Margin="141,34,0,0" VerticalAlignment="Top"/>
<TextBox SelectionChanged="SearchCloseFriendsTextBox_SelectionChanged" x:Name="searchCloseFriendsTextBox" FontSize="20" Background="LightGray" HorizontalAlignment="Left" Margin="141,82,0,0" TextWrapping="Wrap" Text="Search" VerticalAlignment="Top" Width="259"/>
<Button x:Name="addNewCloseFriendButton" Content="Add" HorizontalAlignment="Left" Margin="626,82,0,0" VerticalAlignment="Top" Height="29" Width="48" Click="AddNewCloseFriendButton_Click"/>
<Button x:Name="removeCloseFriendButton" Content="Remove" HorizontalAlignment="Left" Margin="626,131,0,0" VerticalAlignment="Top" Height="30" Width="49" Click="RemoveCloseFriendButton_Click"/>
<ListView x:Name="closeFriendsListView" d:ItemsSource="{d:SampleData ItemCount=5}" Margin="141,131,275,130">
<ListView.View>
<GridView>
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</UserControl>
@@ -0,0 +1,152 @@
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.CloseFriends_GUI
{
/// <summary>
/// Interaction logic for CloseFriendsSection_UserControl.xaml
/// </summary>
public partial class CloseFriendsSection_UserControl : UserControl
{
private User currentConnectedUser;
private ProfileNetworkInfoService profileNetworkInfoService;
public CloseFriendsSection_UserControl(User u, ProfileNetworkInfoService service)
{
InitializeComponent();
this.currentConnectedUser = u;
this.profileNetworkInfoService = service;
PopulateCloseFriends();
}
public void PopulateCloseFriends()
{
if (searchCloseFriendsTextBox.Text.Length > 0 && profileNetworkInfoService != null)
{
// closeFriendsListView.Items.Clear();
// UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
// foreach (var user in profileNetworkInfoService.GetAllUsers())
// {
// bool isCloseFriend = false;
// foreach (var closeFriend in profile.closeFriendsProfiles)
// {
// if (closeFriend.user.username == user.username)
// isCloseFriend = true;
// }
// if (!isCloseFriend)
// {
// //non close friend image
// closeFriendsListView.Items.Add(new { Username = user.username, ImagePath = "../../images/round_checkBox.jpeg" });
// }
// else
// {
// //close firend image
// closeFriendsListView.Items.Add(new { Username = user.username, ImagePath = "../../images/filled_round_checkBox.jpg" });
// }
// }
closeFriendsListView.Items.Clear();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
foreach (var closeFriend in profile.CloseFriendsProfiles)
{
if (closeFriend.User.Username.Contains(searchCloseFriendsTextBox.Text))
{
closeFriendsListView.Items.Add(closeFriend.User.Username);
}
}
}
}
private void SearchCloseFriendsTextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
PopulateCloseFriends();
}
private void AddNewCloseFriendButton_Click(object sender, RoutedEventArgs e)
{
if (searchCloseFriendsTextBox.Text.Length > 0 && profileNetworkInfoService != null)
{
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(currentConnectedUser);
bool usernameExists = false;
foreach (var user in profileNetworkInfoService.GetAllUsers())
{
if (user.Username == searchCloseFriendsTextBox.Text)
{
usernameExists = true;
}
}
if (!usernameExists)
{
MessageBox.Show("Error: User with this username does not exist");
}
else
{
bool alreadyCloseFriend = false;
foreach (var closeFriend in profile.CloseFriendsProfiles)
{
if (closeFriend.User.Username == searchCloseFriendsTextBox.Text)
{
alreadyCloseFriend = true;
}
}
if (alreadyCloseFriend)
{
MessageBox.Show("Error: User is already your close friend");
}
else
{
CloseFriendProfile closeFriendToAdd = new CloseFriendProfile(profileNetworkInfoService.GetUserByName(searchCloseFriendsTextBox.Text), DateTime.Now);
profile.CloseFriendsProfiles.Add(closeFriendToAdd);
profileNetworkInfoService.SaveDataIntoXML();
PopulateCloseFriends();
}
}
}
}
private void RemoveCloseFriendButton_Click(object sender, RoutedEventArgs e)
{
string selectedCloseFriendUsername = closeFriendsListView.SelectedItem.ToString();
UserProfileSocialNetworkInfo profile = profileNetworkInfoService.GetProfileSocialNetworkInfoCurrentUser(this.currentConnectedUser);
profileNetworkInfoService.RemoveCloseFriendFromCurrentUser(profile, profileNetworkInfoService.GetCloseFriendByName(profile, selectedCloseFriendUsername));
profileNetworkInfoService.SaveDataIntoXML();
closeFriendsListView.Items.Clear(); // reset the list view
foreach (var closeFriend in profile.CloseFriendsProfiles)
{
closeFriendsListView.Items.Add(closeFriend.User.Username);
// foreach (var groupMember in group.groupMembers)
// {
// groupMembersListView.Items.Add(groupMember.username);
// }
}
}
}
}