creating presence, not working transition to presence

This commit is contained in:
Dasha06 2024-12-22 15:37:22 +03:00
parent 0d902b6f48
commit 38cf16c345
56 changed files with 210 additions and 28 deletions

View File

@ -7,6 +7,7 @@ using presence.data.RemoteData.RemoteDataBase;
using presence.data.Repository; using presence.data.Repository;
using presence.domain.UseCase; using presence.domain.UseCase;
using Presence.Desktop.ViewModels; using Presence.Desktop.ViewModels;
using ReactiveUI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -23,8 +24,10 @@ namespace Presence.Desktop.DI
.AddDbContext<RemoteDataBaseContext>() .AddDbContext<RemoteDataBaseContext>()
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>() .AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>() .AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
.AddTransient<GroupUseCase>()
.AddTransient<IGroupUseCase, GroupService>() .AddTransient<IGroupUseCase, GroupService>()
.AddTransient<GroupViewModel>(); .AddTransient<GroupViewModel>()
.AddTransient<PresenceViewModel>();
} }
} }
} }

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Presence.Desktop.Models
{
public class PresencePresenter
{
public DateOnly Date { get; set; }
public int ClassNumber { get; set; }
public bool IsAttendence { get; set; }
public UserPresenter? User { get; set; }
}
}

View File

@ -11,5 +11,6 @@ namespace Presence.Desktop.Models
public int Id{ get; set; } public int Id{ get; set; }
public string Name { get; set; } public string Name { get; set; }
public GroupPresenter Group { get; set; } public GroupPresenter Group { get; set; }
public PresencePresenter Presence { get; set; }
} }
} }

View File

@ -11,11 +11,15 @@ using System.Reactive.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Avalonia.Controls.Selection; using Avalonia.Controls.Selection;
using presence.data.RemoteData.RemoteDataBase;
using presence.data.Repository;
using presence.domain.UseCase;
namespace Presence.Desktop.ViewModels namespace Presence.Desktop.ViewModels
{ {
public class GroupViewModel : ViewModelBase, IRoutableViewModel public class GroupViewModel : ViewModelBase, IRoutableViewModel
{ {
private readonly RemoteDataBaseContext _remoteDatabaseContext;
public ICommand OpenFileDialog { get; } public ICommand OpenFileDialog { get; }
public Interaction<string?, string?> SelectFileInteraction => _SelectFileInteraction; public Interaction<string?, string?> SelectFileInteraction => _SelectFileInteraction;
public readonly Interaction<string?, string?> _SelectFileInteraction; public readonly Interaction<string?, string?> _SelectFileInteraction;
@ -48,10 +52,12 @@ namespace Presence.Desktop.ViewModels
public ICommand RemoveUserCommand { get; } public ICommand RemoveUserCommand { get; }
public ICommand EditUserCommand { get; } public ICommand EditUserCommand { get; }
public ICommand RemoveAllSelectedCommand { get; } public ICommand RemoveAllSelectedCommand { get; }
public ICommand NavigateToPresenceCommand { get; }
public GroupViewModel(IGroupUseCase groupUseCase) public GroupViewModel(IGroupUseCase groupUseCase, RemoteDataBaseContext remoteDataBaseContext)
{ {
_groupUseCase = groupUseCase; _groupUseCase = groupUseCase;
_remoteDatabaseContext = remoteDataBaseContext;
_SelectFileInteraction = new Interaction<string?, string?>(); _SelectFileInteraction = new Interaction<string?, string?>();
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile); OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
@ -73,6 +79,7 @@ namespace Presence.Desktop.ViewModels
RemoveUserCommand = ReactiveCommand.Create<UserPresenter>(RemoveUser); RemoveUserCommand = ReactiveCommand.Create<UserPresenter>(RemoveUser);
EditUserCommand = ReactiveCommand.Create<UserPresenter>(EditUser); EditUserCommand = ReactiveCommand.Create<UserPresenter>(EditUser);
RemoveAllSelectedCommand = ReactiveCommand.Create(RemoveAllSelected); RemoveAllSelectedCommand = ReactiveCommand.Create(RemoveAllSelected);
NavigateToPresenceCommand = ReactiveCommand.Create(NavigateToPresence);
} }
private void SetUsers() private void SetUsers()
@ -154,5 +161,13 @@ namespace Presence.Desktop.ViewModels
RefreshGroups(); RefreshGroups();
SetUsers(); SetUsers();
} }
private void NavigateToPresence()
{
var groupRepository = new SQLGroupRepositoryImpl(_remoteDatabaseContext);
var groupUseCase = new GroupUseCase(groupRepository);
HostScreen.Router.Navigate.Execute(new PresenceViewModel(groupUseCase));
}
} }
} }

View File

@ -1,13 +1,106 @@
using ReactiveUI; using Avalonia.Data.Converters;
using presence.data.RemoteData.RemoteDataBase.DAO;
using presence.domain.Models;
using presence.domain.UseCase;
using Presence.Desktop.Models;
using Presence.Desktop.ViewModels;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Reactive;
namespace Presence.Desktop.ViewModels; namespace Presence.Desktop.ViewModels
public class PresenceViewModel: ViewModelBase, IRoutableViewModel
{ {
public string? UrlPathSegment { get; } public class PresenceViewModel : ViewModelBase, IRoutableViewModel
public IScreen HostScreen { get; } {
public string? UrlPathSegment { get; } = "Presence";
public IScreen HostScreen { get; }
private readonly GroupUseCase _groupUseCase;
} private readonly PresenceUseCase _presenceUseCase;
public ObservableCollection<PresencePresenter> AttendanceRecords { get; set; } = new();
public ObservableCollection<GroupPresenter> Groups { get; set; } = new();
private GroupPresenter? _selectedGroup;
public GroupPresenter? SelectedGroup
{
get => _selectedGroup;
set
{
this.RaiseAndSetIfChanged(ref _selectedGroup, value);
FilterAttendanceRecords();
}
}
private DateOnly? _selectedDate;
public DateOnly? SelectedDate
{
get => _selectedDate;
set
{
this.RaiseAndSetIfChanged(ref _selectedDate, value);
FilterAttendanceRecords();
}
}
public ReactiveCommand<Unit, Unit> NavigateBackCommand { get; }
public PresenceViewModel(GroupUseCase groupUseCase)
{
_groupUseCase = groupUseCase;
NavigateBackCommand = ReactiveCommand.Create(() => { });
LoadGroups();
}
private void LoadGroups()
{
Groups.Clear();
var groups = _groupUseCase.GetAllGroups();
foreach (var group in groups)
{
Groups.Add(new GroupPresenter
{
Id = group.Id,
Name = group.Name
});
}
}
private void FilterAttendanceRecords()
{
if (SelectedGroup == null || SelectedDate == null)
{
AttendanceRecords.Clear();
return;
}
var records = _presenceUseCase.GetPresenceByGroupAndDate(
SelectedGroup.Id,
SelectedDate.Value);
AttendanceRecords.Clear();
foreach (var record in records)
{
AttendanceRecords.Add(new PresencePresenter
{
Date = record.Date,
ClassNumber = record.ClassNumber,
IsAttendence = record.IsAttendence,
User = new UserPresenter
{
Id = record.User.Id,
Name= record.User.FIO
}
});
}
}
}
}

View File

@ -18,6 +18,11 @@
Margin="10,10,0,0" Margin="10,10,0,0"
Foreground="Black" Foreground="Black"
IsVisible="{Binding SelectedGroupItem, Converter={x:Static ObjectConverters.IsNotNull}}"/> IsVisible="{Binding SelectedGroupItem, Converter={x:Static ObjectConverters.IsNotNull}}"/>
<Button Content="Перейти к посещаемости"
Command="{Binding NavigateToPresenceCommand}"
HorizontalAlignment="Right"
Margin="0,10,0,0"
Foreground="Black"/>
</StackPanel> </StackPanel>
<StackPanel <StackPanel
Spacing="10" Spacing="10"

View File

@ -2,7 +2,37 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:Presence.Desktop.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Presence.Desktop.Views.PresenceView"> x:Class="Presence.Desktop.Views.PresenceView"
Welcome to Avalonia! x:DataType="vm:PresenceViewModel">
<Grid RowDefinitions="Auto, Auto, *, Auto" Margin="10">
<StackPanel Orientation="Horizontal" Grid.Row="0" Spacing="10">
<!-- Выбор группы -->
<ComboBox ItemsSource="{Binding Groups}" SelectedItem="{Binding SelectedGroup}" Width="200" PlaceholderText="Выберите группу">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Календарь -->
<Calendar SelectedDate="{Binding SelectedDate}" />
</StackPanel>
<!-- Таблица с посещаемостью -->
<DataGrid Grid.Row="2" AutoGenerateColumns="False" ItemsSource="{Binding AttendanceRecords}" CanUserSortColumns="True">
<DataGrid.Columns>
<DataGridTextColumn Header="Дата" Binding="{Binding Date}" />
<DataGridTextColumn Header="Номер урока" Binding="{Binding ClassNumber}" />
<DataGridTextColumn Header="ФИО" Binding="{Binding User.Name}" />
<!-- Тип посещаемости -->
<DataGridCheckBoxColumn Header="Тип посещаемости" Binding="{Binding IsAttendence, Mode=TwoWay}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</UserControl> </UserControl>

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+7022af564df3af3bd7b3d3e4904e100f6e6294bc")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0d902b6f481ae89f72a8bbdfe147247c3696808e")]
[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 @@
cfdc02e4f88afe979f5985745301d96a88e08b3174daf2797998e1b5cb3ca0b0 48554ad8782293b7cc2f242624ddfa361309e094aa6ac7b85c8ebaf337a70f40

View File

@ -1 +1 @@
e68626bd1a98dbdea1f40f374f2417a325447b8270eac3ee295a31c6c470b799 0495b34aad8f14f248b68664d83675aa4c43aa8757ddb475b703d4e606ccfb0f

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+7022af564df3af3bd7b3d3e4904e100f6e6294bc")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0d902b6f481ae89f72a8bbdfe147247c3696808e")]
[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 @@
def5d5af8ca7ee1949b786807a9b9f85a2aa893d54e610b79480bc0b442186f2 b1eb225ffe5f3f4f77eb6e686327399e3b9adee1531fc1962f9f2de9f983cf57

View File

@ -17,6 +17,7 @@ namespace presence.data.Repository
bool DeletePresenceByGroup(int groupId); bool DeletePresenceByGroup(int groupId);
bool DeletePresenceByUser(int userId); bool DeletePresenceByUser(int userId);
bool DeletePresenceByDate(DateOnly startData, DateOnly endData); bool DeletePresenceByDate(DateOnly startData, DateOnly endData);
void UpdateAttendance(PresenceDao presence);
} }

View File

@ -121,5 +121,18 @@ namespace presence.data.Repository
return false; return false;
} }
public void UpdateAttendance(PresenceDao presence)
{
if (presence == null) throw new ArgumentNullException(nameof(presence));
var nowPresence = _remoteDatabaseContext.Presences.FirstOrDefault(p => p.PresenceId == presence.PresenceId);
if (nowPresence == null)
throw new ArgumentNullException(nameof(presence));
nowPresence.IsAttendence = presence.IsAttendence;
_remoteDatabaseContext.SaveChanges();
}
} }
} }

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ 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+7022af564df3af3bd7b3d3e4904e100f6e6294bc")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0d902b6f481ae89f72a8bbdfe147247c3696808e")]
[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")]
// Generated by the MSBuild WriteCodeFragment class. // Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
752980e9ba0fc45a48f86e9fb9c05988e1c4ae8363fb35dfaf09a6f519c41602 491a118ec5543e51089962ed9bcdfa5b8cf88b30968e339c3fc43e732215e55c

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -229,5 +229,10 @@ namespace presence.domain.UseCase
{ {
return _presenceRepository.DeletePresenceByDate(startData, endData); return _presenceRepository.DeletePresenceByDate(startData, endData);
} }
public void UpdateAttendance(PresenceDao presence)
{
_presenceRepository.UpdateAttendance(presence);
}
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,10 +13,10 @@ 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+7022af564df3af3bd7b3d3e4904e100f6e6294bc")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0d902b6f481ae89f72a8bbdfe147247c3696808e")]
[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")]
// Generated by the MSBuild WriteCodeFragment class. // Создано классом WriteCodeFragment MSBuild.

View File

@ -1 +1 @@
dc648c33d8b05f8cbaa3410cee6e9ca878027ccb31fe07df25b4871f24fbbf66 3879d5ba26c2c5c5a09dc7d172821c4e08e4aefc11c2344ccecf9e4847449c91

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+7022af564df3af3bd7b3d3e4904e100f6e6294bc")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0d902b6f481ae89f72a8bbdfe147247c3696808e")]
[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 @@
7dcf2234c5025f4297ae3529e7e05ecddaafe8eda1311843fc42af2cbe4afbb9 312fc1680bcd1ec62bf371b791280808df779a4ccf1606d84ea5fb3bb5f77969

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+7022af564df3af3bd7b3d3e4904e100f6e6294bc")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0d902b6f481ae89f72a8bbdfe147247c3696808e")]
[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 @@
6af47f6a2108a9fdf37e6d5359dbde1827d2db002e4e6ee422264c0f631befa8 519394075c67a7ab9c81664396c682f0d50cbaab063eb07cdd1c12824d46a3ff