context_menu

This commit is contained in:
Your Name 2024-12-22 22:41:45 +03:00
parent 80e6836fdd
commit e09931058b
51 changed files with 149 additions and 60 deletions

View File

@ -11,7 +11,7 @@ using System.Threading.Tasks;
public class GroupPresenter public class GroupPresenter
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string? Name { get; set; }
public IEnumerable<UserPresenter>? users { get; set; } = null; public IEnumerable<UserPresenter>? users { get; set; } = null;
} }
} }

View File

@ -14,6 +14,6 @@ using System.Threading.Tasks;
public bool IsAttedance {get; set; } public bool IsAttedance {get; set; }
public DateOnly Date {get; set; } public DateOnly Date {get; set; }
public int LessonNumber {get; set; } public int LessonNumber {get; set; }
public UserPresenter user { get; set; } public UserPresenter? user { get; set; }
} }
} }

View File

@ -18,7 +18,7 @@ namespace Presence.Desktop.Models
} }
public Guid Guid { get; set; } public Guid Guid { get; set; }
public string Name { get; set; } public string? Name { get; set; }
public GroupPresenter Group { get; set; } public GroupPresenter? Group { get; set; }
} }
} }

View File

@ -12,6 +12,8 @@ using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using Avalonia.Controls; using Avalonia.Controls;
using Presence.Desktop.Views;
using Avalonia.Input;
namespace Presence.Desktop.ViewModels namespace Presence.Desktop.ViewModels
{ {
@ -19,7 +21,6 @@ namespace Presence.Desktop.ViewModels
{ {
private readonly IGroupUseCase _groupUseCase; private readonly IGroupUseCase _groupUseCase;
private readonly IUserUseCase _userUseCase; private readonly IUserUseCase _userUseCase;
private readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
private ObservableCollection<GroupPresenter> _groups; private ObservableCollection<GroupPresenter> _groups;
public ObservableCollection<GroupPresenter> Groups => _groups; public ObservableCollection<GroupPresenter> Groups => _groups;
@ -44,9 +45,44 @@ namespace Presence.Desktop.ViewModels
set => this.RaiseAndSetIfChanged(ref _selectedSecondItem, value); set => this.RaiseAndSetIfChanged(ref _selectedSecondItem, value);
} }
private UserPresenter? _selectedUser;
public UserPresenter? SelectedUser
{
get => _selectedUser;
set => this.RaiseAndSetIfChanged(ref _selectedUser, value);
}
private ObservableCollection<UserPresenter> _selectedUsers = new ObservableCollection<UserPresenter>();
public ObservableCollection<UserPresenter> SelectedUsers
{
get => _selectedUsers;
set => this.RaiseAndSetIfChanged(ref _selectedUsers, value);
}
private bool _isMultipleUsersSelected;
public bool IsMultipleUsersSelected
{
get => _isMultipleUsersSelected;
set => this.RaiseAndSetIfChanged(ref _isMultipleUsersSelected, value);
}
private string? _newFIO;
public string? NewFIO
{
get => _newFIO;
set => this.RaiseAndSetIfChanged(ref _newFIO, value);
}
public UserPresenter? SelectedUserForUpdate
{
get => SelectedUsers?.FirstOrDefault();
set => this.RaiseAndSetIfChanged(ref _selectedUser, value);
}
public ReactiveCommand<Unit, Unit> ButtonRemoveUsersByGroup { get; } public ReactiveCommand<Unit, Unit> ButtonRemoveUsersByGroup { get; }
public ReactiveCommand<Unit, Unit> ImportStudentsCommand { get; } public ReactiveCommand<Unit, Unit> ImportStudentsCommand { get; }
public ReactiveCommand<Unit, Unit> RemoveUsersContext { get; } public ReactiveCommand<IEnumerable<UserPresenter>, Unit> RemoveSelectedUsersCommand { get; }
public ReactiveCommand<UserPresenter, Unit> UpdateUserFIOCommand { get; }
public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase) public GroupViewModel(IGroupUseCase groupUseCase, IUserUseCase userUseCase)
{ {
@ -68,29 +104,15 @@ namespace Presence.Desktop.ViewModels
this.WhenAnyValue(vm => vm.SelectedSecondItem) this.WhenAnyValue(vm => vm.SelectedSecondItem)
.Subscribe(_ => SetUsers()); .Subscribe(_ => SetUsers());
this.WhenAnyValue(vm => vm.SelectedUsers.Count)
.Subscribe(count => IsMultipleUsersSelected = count > 1);
SelectedSecondItem = _secondComboBoxItems.First(); SelectedSecondItem = _secondComboBoxItems.First();
ButtonRemoveUsersByGroup = ReactiveCommand.Create(() => RemoveUsersByGroup()); ButtonRemoveUsersByGroup = ReactiveCommand.Create(() => RemoveUsersByGroup());
ImportStudentsCommand = ReactiveCommand.CreateFromTask(async () => await ImportStudents()); ImportStudentsCommand = ReactiveCommand.CreateFromTask(async () => await ImportStudents());
RemoveUsersContext = ReactiveCommand.Create(() => RemoveUsersByContextMenu()); RemoveSelectedUsersCommand = ReactiveCommand.Create<IEnumerable<UserPresenter>>(DeleteUsers);
} UpdateUserFIOCommand = ReactiveCommand.Create<UserPresenter>(UpdateUserFIO);
private void RemoveUsersByContextMenu(){
if (SelectedGroupItem == null || SelectedGroupItem.Id == null) return;
var selectedUsers = Users.Where(u => u.IsSelected).ToList();
foreach (var user in selectedUsers)
{
var isRemoved = _userUseCase.RemoveUserByFIOnGroup(user.Name, SelectedGroupItem.Id);
if (isRemoved)
{
Users.Remove(user);
}
}
RefreshGroups();
SetUsers();
} }
private void SetUsers() private void SetUsers()
@ -117,7 +139,7 @@ namespace Presence.Desktop.ViewModels
private void RefreshGroups() private void RefreshGroups()
{ {
_groupPresentersDataSource.Clear(); _groups.Clear();
foreach (var group in _groupUseCase.GetAllGroupsWithUsers()) foreach (var group in _groupUseCase.GetAllGroupsWithUsers())
{ {
@ -132,10 +154,8 @@ namespace Presence.Desktop.ViewModels
Group = new GroupPresenter { Id = group.ID, Name = group.Name } Group = new GroupPresenter { Id = group.ID, Name = group.Name }
}).ToList() }).ToList()
}; };
_groupPresentersDataSource.Add(groupPresenter); _groups.Add(groupPresenter);
} }
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
} }
private void RemoveUsersByGroup() private void RemoveUsersByGroup()
@ -147,7 +167,6 @@ namespace Presence.Desktop.ViewModels
SetUsers(); SetUsers();
} }
//import users
private async System.Threading.Tasks.Task ImportStudents() private async System.Threading.Tasks.Task ImportStudents()
{ {
if (SelectedGroupItem == null || SelectedGroupItem.Id == null) return; if (SelectedGroupItem == null || SelectedGroupItem.Id == null) return;
@ -193,6 +212,64 @@ namespace Presence.Desktop.ViewModels
} }
} }
private void DeleteUsers(IEnumerable<UserPresenter> users)
{
if (users == null) return;
var usersToDelete = new List<UserPresenter>(users);
foreach (var user in usersToDelete)
{
var isDeleted = _userUseCase.RemoveUserByGuid(user.Guid);
if (isDeleted)
{
Users.Remove(user);
}
}
}
private void DeleteUser(UserPresenter user) {
if (user == null) return;
var isDeleted = _userUseCase.RemoveUserByGuid(user.Guid);
if (isDeleted) {
Users.Remove(user);
}
}
private void UpdateUserFIO(UserPresenter user)
{
Console.WriteLine("start");
if (user == null || string.IsNullOrWhiteSpace(NewFIO)) return;
user.Name = NewFIO;
var updatedUser = new User
{
Guid = user.Guid,
FIO = NewFIO,
Group = new Group
{
ID = SelectedGroupItem.Id,
Name = SelectedGroupItem.Name
}
};
var isUpdated = _userUseCase.UpdateUser(updatedUser);
Console.WriteLine("end");
if (isUpdated != null)
{
NewFIO = string.Empty;
// SelectedUsers.Clear(); // Очистить выбранных пользователей
// SelectedUser = null; // Обнулить выбранного пользователя
// SelectedUserForUpdate = null;
RefreshGroups();
SetUsers();
}
}
public string? UrlPathSegment { get; } public string? UrlPathSegment { get; }
public IScreen HostScreen { get; } public IScreen HostScreen { get; }
} }

View File

@ -13,21 +13,17 @@
<DockPanel Background="Azure"> <DockPanel Background="Azure">
<StackPanel Width="200" DockPanel.Dock="Right" HorizontalAlignment="Center" Background="Gray"> <StackPanel Width="200" DockPanel.Dock="Right" HorizontalAlignment="Center" Background="Gray">
<Button Content="remove" HorizontalAlignment="Center" Margin="10" Command="{Binding ButtonRemoveUsersByGroup}"/> <Button Content="Remove Users by Group" HorizontalAlignment="Center" Margin="10" Command="{Binding ButtonRemoveUsersByGroup}"/>
<Button Content="create" HorizontalAlignment="Center" Margin="10" Command="{Binding ImportStudentsCommand}"/> <Button Content="Import Students" HorizontalAlignment="Center" Margin="10" Command="{Binding ImportStudentsCommand}"/>
</StackPanel> </StackPanel>
<StackPanel DockPanel.Dock="Bottom"> <StackPanel DockPanel.Dock="Bottom">
<TextBlock Text="List ↑" HorizontalAlignment="Center"/> <TextBlock Text="List ↑" HorizontalAlignment="Center"/>
</StackPanel> </StackPanel>
<StackPanel <StackPanel Spacing="10" HorizontalAlignment="Center" DockPanel.Dock="Top" Orientation="Horizontal">
Spacing="10"
HorizontalAlignment="Center"
DockPanel.Dock="Top"
Orientation="Horizontal">
<TextBlock Text="Combobox ->"/> <TextBlock Text="Combobox ->"/>
<ComboBox ItemsSource="{Binding Groups}" SelectedValue="{Binding SelectedGroupItem}"> <ComboBox ItemsSource="{Binding Groups}" SelectedValue="{Binding SelectedGroupItem}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name}"/> <TextBlock Text="{Binding Name}"/>
@ -45,20 +41,33 @@
</StackPanel> </StackPanel>
<Border> <Border>
<ListBox Background="Bisque" ItemsSource="{Binding Users}" SelectionMode="Multiple"> <ListBox Background="Bisque"
<ListBox.ContextMenu> ItemsSource="{Binding Users}"
<ContextMenu> SelectedItems="{Binding SelectedUsers}"
<MenuItem Header="Remove" Command="{Binding RemoveUsersContext}"/> SelectionMode="Multiple">
</ContextMenu>
</ListBox.ContextMenu>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Margin="5">
<CheckBox IsChecked="{Binding IsSelected}" /> <TextBlock Text="{Binding Name}" Foreground="Black" />
<TextBlock Text="{Binding Name}" FontSize="16" Foreground="Black"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete User"
Command="{Binding RemoveSelectedUsersCommand}"
CommandParameter="{Binding SelectedUsers}" />
<MenuItem Header="Update FIO">
<StackPanel>
<TextBox Text="{Binding NewFIO, Mode=TwoWay}" Width="150" />
<Button Content="Update"
Command="{Binding UpdateUserFIOCommand}"
CommandParameter="{Binding SelectedUserForUpdate}" />
</StackPanel>
</MenuItem>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox> </ListBox>
</Border> </Border>
</DockPanel> </DockPanel>

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Presence.Desktop")] [assembly: System.Reflection.AssemblyCompanyAttribute("Presence.Desktop")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9fb14f26f76520b93e2dffe32b9920452b1164eb")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyProductAttribute("Presence.Desktop")] [assembly: System.Reflection.AssemblyProductAttribute("Presence.Desktop")]
[assembly: System.Reflection.AssemblyTitleAttribute("Presence.Desktop")] [assembly: System.Reflection.AssemblyTitleAttribute("Presence.Desktop")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
b7498df5d2206005112870d5c2c73b5108e5527e6c157c6bfa81adcb4e354c81 485d72bd8c17c9c53806b7884b4db72daae02b7b80944f5245faea27c33dd0a5

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("console_ui")] [assembly: System.Reflection.AssemblyCompanyAttribute("console_ui")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9fb14f26f76520b93e2dffe32b9920452b1164eb")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyProductAttribute("console_ui")] [assembly: System.Reflection.AssemblyProductAttribute("console_ui")]
[assembly: System.Reflection.AssemblyTitleAttribute("console_ui")] [assembly: System.Reflection.AssemblyTitleAttribute("console_ui")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
168f5efe473362e291e5e71f2ddeec86688eb46022542ef7888a19812808d8d7 b424d19706bc03d5048d7bd39d95e5a8c436155447941510c260b9e9fc7fc5ae

View File

@ -55,8 +55,11 @@ namespace Demo.Data.Repository
return true; return true;
} }
public bool RemoveUserByFIOnGroup(string FIO, int groupID){ public bool RemoveUserByFIOnGroup(string FIO, int groupID)
{
var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.FIO == FIO && x.GroupID == groupID); var userDAO = _remoteDatabaseContext.Users.FirstOrDefault(x => x.FIO == FIO && x.GroupID == groupID);
if (userDAO == null) return false; // Если пользователь не найден, возвращаем false
_remoteDatabaseContext.Users.Remove(userDAO); _remoteDatabaseContext.Users.Remove(userDAO);
_remoteDatabaseContext.SaveChanges(); _remoteDatabaseContext.SaveChanges();
return true; return true;

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("data")] [assembly: System.Reflection.AssemblyCompanyAttribute("data")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9fb14f26f76520b93e2dffe32b9920452b1164eb")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyProductAttribute("data")] [assembly: System.Reflection.AssemblyProductAttribute("data")]
[assembly: System.Reflection.AssemblyTitleAttribute("data")] [assembly: System.Reflection.AssemblyTitleAttribute("data")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
c72b092daa6ba175d3015381913771c1e175cbd23d956f6f46fe3a4f2b74b730 07948ecd6bcf5c696118b2bb51525cf0e6a08c9edade60282c369c24c0f7467a

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("domain")] [assembly: System.Reflection.AssemblyCompanyAttribute("domain")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9fb14f26f76520b93e2dffe32b9920452b1164eb")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyProductAttribute("domain")] [assembly: System.Reflection.AssemblyProductAttribute("domain")]
[assembly: System.Reflection.AssemblyTitleAttribute("domain")] [assembly: System.Reflection.AssemblyTitleAttribute("domain")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
a090e784cd672ac7f4d063a1614d0b2085d1bef552d25f58907fdd2eb3060720 79920cd1d0e66f37855197a0ebcf05abf060743faccf786a348a4b7c76132a45

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")] [assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9fb14f26f76520b93e2dffe32b9920452b1164eb")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyProductAttribute("presence_api")] [assembly: System.Reflection.AssemblyProductAttribute("presence_api")]
[assembly: System.Reflection.AssemblyTitleAttribute("presence_api")] [assembly: System.Reflection.AssemblyTitleAttribute("presence_api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
7c4d0c2c4bfbba3e9226dc05c7c6db1bcce4df4ad872df73c45f5e0b076c25bd 9efba3c6d270d9bc34c009a828e26d9aad4ab4d560e61fe61a3104c6e2d5f384

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("ui")] [assembly: System.Reflection.AssemblyCompanyAttribute("ui")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9fb14f26f76520b93e2dffe32b9920452b1164eb")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+80e6836fdd04e3d1b872969d7d238179bae0c673")]
[assembly: System.Reflection.AssemblyProductAttribute("ui")] [assembly: System.Reflection.AssemblyProductAttribute("ui")]
[assembly: System.Reflection.AssemblyTitleAttribute("ui")] [assembly: System.Reflection.AssemblyTitleAttribute("ui")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
e2f28b5b9ef339961c4e1f85cf1fc465d19791b59a3da4607c5a8ef82054440f 5fa0ea2517f1689a12f6e89017ac00f1e9ddf9b9ea076339f78ac980571c13f6