context_menu
This commit is contained in:
parent
80e6836fdd
commit
e09931058b
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
public class GroupPresenter
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public IEnumerable<UserPresenter>? users { get; set; } = null;
|
||||
}
|
||||
}
|
@ -14,6 +14,6 @@ using System.Threading.Tasks;
|
||||
public bool IsAttedance {get; set; }
|
||||
public DateOnly Date {get; set; }
|
||||
public int LessonNumber {get; set; }
|
||||
public UserPresenter user { get; set; }
|
||||
public UserPresenter? user { get; set; }
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ namespace Presence.Desktop.Models
|
||||
}
|
||||
|
||||
public Guid Guid { get; set; }
|
||||
public string Name { get; set; }
|
||||
public GroupPresenter Group { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public GroupPresenter? Group { get; set; }
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Presence.Desktop.Views;
|
||||
using Avalonia.Input;
|
||||
|
||||
namespace Presence.Desktop.ViewModels
|
||||
{
|
||||
@ -19,7 +21,6 @@ namespace Presence.Desktop.ViewModels
|
||||
{
|
||||
private readonly IGroupUseCase _groupUseCase;
|
||||
private readonly IUserUseCase _userUseCase;
|
||||
private readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
|
||||
|
||||
private ObservableCollection<GroupPresenter> _groups;
|
||||
public ObservableCollection<GroupPresenter> Groups => _groups;
|
||||
@ -44,9 +45,44 @@ namespace Presence.Desktop.ViewModels
|
||||
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> 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)
|
||||
{
|
||||
@ -68,29 +104,15 @@ namespace Presence.Desktop.ViewModels
|
||||
this.WhenAnyValue(vm => vm.SelectedSecondItem)
|
||||
.Subscribe(_ => SetUsers());
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedUsers.Count)
|
||||
.Subscribe(count => IsMultipleUsersSelected = count > 1);
|
||||
|
||||
SelectedSecondItem = _secondComboBoxItems.First();
|
||||
|
||||
ButtonRemoveUsersByGroup = ReactiveCommand.Create(() => RemoveUsersByGroup());
|
||||
ImportStudentsCommand = ReactiveCommand.CreateFromTask(async () => await ImportStudents());
|
||||
RemoveUsersContext = ReactiveCommand.Create(() => RemoveUsersByContextMenu());
|
||||
}
|
||||
|
||||
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();
|
||||
RemoveSelectedUsersCommand = ReactiveCommand.Create<IEnumerable<UserPresenter>>(DeleteUsers);
|
||||
UpdateUserFIOCommand = ReactiveCommand.Create<UserPresenter>(UpdateUserFIO);
|
||||
}
|
||||
|
||||
private void SetUsers()
|
||||
@ -117,7 +139,7 @@ namespace Presence.Desktop.ViewModels
|
||||
|
||||
private void RefreshGroups()
|
||||
{
|
||||
_groupPresentersDataSource.Clear();
|
||||
_groups.Clear();
|
||||
|
||||
foreach (var group in _groupUseCase.GetAllGroupsWithUsers())
|
||||
{
|
||||
@ -132,10 +154,8 @@ namespace Presence.Desktop.ViewModels
|
||||
Group = new GroupPresenter { Id = group.ID, Name = group.Name }
|
||||
}).ToList()
|
||||
};
|
||||
_groupPresentersDataSource.Add(groupPresenter);
|
||||
_groups.Add(groupPresenter);
|
||||
}
|
||||
|
||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||
}
|
||||
|
||||
private void RemoveUsersByGroup()
|
||||
@ -147,7 +167,6 @@ namespace Presence.Desktop.ViewModels
|
||||
SetUsers();
|
||||
}
|
||||
|
||||
//import users
|
||||
private async System.Threading.Tasks.Task ImportStudents()
|
||||
{
|
||||
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 IScreen HostScreen { get; }
|
||||
}
|
||||
|
@ -13,21 +13,17 @@
|
||||
|
||||
<DockPanel Background="Azure">
|
||||
<StackPanel Width="200" DockPanel.Dock="Right" HorizontalAlignment="Center" Background="Gray">
|
||||
<Button Content="remove" HorizontalAlignment="Center" Margin="10" Command="{Binding ButtonRemoveUsersByGroup}"/>
|
||||
<Button Content="create" HorizontalAlignment="Center" Margin="10" Command="{Binding ImportStudentsCommand}"/>
|
||||
<Button Content="Remove Users by Group" HorizontalAlignment="Center" Margin="10" Command="{Binding ButtonRemoveUsersByGroup}"/>
|
||||
<Button Content="Import Students" HorizontalAlignment="Center" Margin="10" Command="{Binding ImportStudentsCommand}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel DockPanel.Dock="Bottom">
|
||||
<TextBlock Text="List ↑" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel
|
||||
Spacing="10"
|
||||
HorizontalAlignment="Center"
|
||||
DockPanel.Dock="Top"
|
||||
Orientation="Horizontal">
|
||||
<StackPanel Spacing="10" HorizontalAlignment="Center" DockPanel.Dock="Top" Orientation="Horizontal">
|
||||
<TextBlock Text="Combobox ->"/>
|
||||
<ComboBox ItemsSource="{Binding Groups}" SelectedValue="{Binding SelectedGroupItem}">
|
||||
<ComboBox ItemsSource="{Binding Groups}" SelectedValue="{Binding SelectedGroupItem}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
@ -45,20 +41,33 @@
|
||||
</StackPanel>
|
||||
|
||||
<Border>
|
||||
<ListBox Background="Bisque" ItemsSource="{Binding Users}" SelectionMode="Multiple">
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Remove" Command="{Binding RemoveUsersContext}"/>
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
<ListBox Background="Bisque"
|
||||
ItemsSource="{Binding Users}"
|
||||
SelectedItems="{Binding SelectedUsers}"
|
||||
SelectionMode="Multiple">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox IsChecked="{Binding IsSelected}" />
|
||||
<TextBlock Text="{Binding Name}" FontSize="16" Foreground="Black"/>
|
||||
<StackPanel Orientation="Horizontal" Margin="5">
|
||||
<TextBlock Text="{Binding Name}" Foreground="Black" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</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>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
|
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.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Presence.Desktop")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("Presence.Desktop")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
b7498df5d2206005112870d5c2c73b5108e5527e6c157c6bfa81adcb4e354c81
|
||||
485d72bd8c17c9c53806b7884b4db72daae02b7b80944f5245faea27c33dd0a5
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("console_ui")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("console_ui")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
168f5efe473362e291e5e71f2ddeec86688eb46022542ef7888a19812808d8d7
|
||||
b424d19706bc03d5048d7bd39d95e5a8c436155447941510c260b9e9fc7fc5ae
|
||||
|
Binary file not shown.
@ -55,8 +55,11 @@ namespace Demo.Data.Repository
|
||||
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);
|
||||
if (userDAO == null) return false; // Если пользователь не найден, возвращаем false
|
||||
|
||||
_remoteDatabaseContext.Users.Remove(userDAO);
|
||||
_remoteDatabaseContext.SaveChanges();
|
||||
return true;
|
||||
|
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("data")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -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.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("domain")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
a090e784cd672ac7f4d063a1614d0b2085d1bef552d25f58907fdd2eb3060720
|
||||
79920cd1d0e66f37855197a0ebcf05abf060743faccf786a348a4b7c76132a45
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("presence_api")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
7c4d0c2c4bfbba3e9226dc05c7c6db1bcce4df4ad872df73c45f5e0b076c25bd
|
||||
9efba3c6d270d9bc34c009a828e26d9aad4ab4d560e61fe61a3104c6e2d5f384
|
||||
|
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("ui")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[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.AssemblyTitleAttribute("ui")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
e2f28b5b9ef339961c4e1f85cf1fc465d19791b59a3da4607c5a8ef82054440f
|
||||
5fa0ea2517f1689a12f6e89017ac00f1e9ddf9b9ea076339f78ac980571c13f6
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user