diff --git a/Presence.Api/Controllers/GroupController.cs b/Presence.Api/Controllers/GroupController.cs deleted file mode 100644 index 142f999..0000000 --- a/Presence.Api/Controllers/GroupController.cs +++ /dev/null @@ -1,45 +0,0 @@ -using domain.Service; -using domain.UseCase; -using domain.Request; -using domain.Service; -using Microsoft.AspNetCore.Mvc; -using Presence.Api.Response; - -namespace Presence.Api.Controllers -{ - [ApiController] - [Route("[controller]/api")] - public class GroupController: ControllerBase - { - private readonly IGroupUseCase _groupService; - - public GroupController(IGroupUseCase groupService) - { - _groupService = groupService; - } - - [HttpGet("/group")] - public async Task> GetAllGroups() - { - var result = _groupService - .GetGroupsWithStudents(); - var response = result - .Select(group => new GroupResponse { - Id = group.Id, - Name = group.Name, - Users = group.Users.Select(user => new UserResponse { - Guid = user.Guid, - Name = user.Name - }).ToList(), - }).ToList(); - return Ok(new GroupResponse()); - } - - [HttpPost("/admin/{groupId}/students")] - public void AddGroup(int groupId, [FromBody] AddGroupRequest addGroupRequest) - { - Console.WriteLine(groupId); - _groupService.AddGroup(addGroupRequest); - } - } -} diff --git a/Presence.Api/Controllers/WeatherForecastController.cs b/Presence.Api/Controllers/WeatherForecastController.cs deleted file mode 100644 index 4ad6679..0000000 --- a/Presence.Api/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Presence.Api.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/Presence.Api/Extensions/ServiceCollectionsExtension.cs b/Presence.Api/Extensions/ServiceCollectionsExtension.cs deleted file mode 100644 index 4321298..0000000 --- a/Presence.Api/Extensions/ServiceCollectionsExtension.cs +++ /dev/null @@ -1,20 +0,0 @@ -using data; -using data.Repository; -using domain.Service; -using domain.UseCase; -using Presence.Api.Controllers; - -namespace Presence.Api.Extensions -{ - public static class ServiceCollectionsExtension - { - public static void AddCommomService(this IServiceCollection services) - { - services - .AddDbContext() - .AddScoped() - .AddScoped() - .AddScoped(); - } - } -} diff --git a/Presence.Api/Presence.Api.csproj b/Presence.Api/Presence.Api.csproj deleted file mode 100644 index 3c0d11b..0000000 --- a/Presence.Api/Presence.Api.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - - - - - - - - diff --git a/Presence.Api/Presence.Api.http b/Presence.Api/Presence.Api.http deleted file mode 100644 index 68c2819..0000000 --- a/Presence.Api/Presence.Api.http +++ /dev/null @@ -1,6 +0,0 @@ -@Presence.Api_HostAddress = http://localhost:5028 - -GET {{Presence.Api_HostAddress}}/weatherforecast/ -Accept: application/json - -### diff --git a/Presence.Api/Program.cs b/Presence.Api/Program.cs deleted file mode 100644 index d640dd2..0000000 --- a/Presence.Api/Program.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Presence.Api.Extensions; - -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -builder.Services.AddCommomService(); - -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(); -} - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); diff --git a/Presence.Api/Properties/launchSettings.json b/Presence.Api/Properties/launchSettings.json deleted file mode 100644 index 10c6513..0000000 --- a/Presence.Api/Properties/launchSettings.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:32613", - "sslPort": 44302 - } - }, - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "http://localhost:5028", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7098;http://localhost:5028", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "launchUrl": "swagger", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/Presence.Api/Response/GroupResponse.cs b/Presence.Api/Response/GroupResponse.cs deleted file mode 100644 index c252f0c..0000000 --- a/Presence.Api/Response/GroupResponse.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Presence.Api.Response -{ - public class GroupResponse - { - public int Id { get; set; } - public string Name { get; set; } - public IEnumerable? Users { get; set; } = null; - } -} diff --git a/Presence.Api/Response/UserResponse.cs b/Presence.Api/Response/UserResponse.cs deleted file mode 100644 index c4f1df2..0000000 --- a/Presence.Api/Response/UserResponse.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Presence.Api.Response -{ - public class UserResponse - { - public Guid Guid { get; set; } - public string Name { get; set; } - } -} diff --git a/Presence.Api/WeatherForecast.cs b/Presence.Api/WeatherForecast.cs deleted file mode 100644 index 86ff197..0000000 --- a/Presence.Api/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Presence.Api -{ - public class WeatherForecast - { - public DateOnly Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} diff --git a/Presence.Api/appsettings.Development.json b/Presence.Api/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/Presence.Api/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/Presence.Api/appsettings.json b/Presence.Api/appsettings.json deleted file mode 100644 index 10f68b8..0000000 --- a/Presence.Api/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/Presence.Desktop/App.axaml.cs b/Presence.Desktop/App.axaml.cs index 2cdb41d..8b4300e 100644 --- a/Presence.Desktop/App.axaml.cs +++ b/Presence.Desktop/App.axaml.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Data.DAO; using Microsoft.Extensions.DependencyInjection; using Presence.Desktop.DI; using Presence.Desktop.ViewModels; @@ -18,13 +19,13 @@ namespace Presence.Desktop public override void OnFrameworkInitializationCompleted() { var serviceCollection = new ServiceCollection(); - serviceCollection.AddCommonService(); + serviceCollection.AddPresenceService(); var services = serviceCollection.BuildServiceProvider(); - var maimViewModel = services.GetRequiredService(); + var maimViewModel = services.GetRequiredService(); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow = new GroupView() + desktop.MainWindow = new PresenceView() { DataContext = maimViewModel, }; diff --git a/Presence.Desktop/DI/ServiceCollectionExtensions.cs b/Presence.Desktop/DI/ServiceCollectionExtensions.cs index 5fd078a..feb197d 100644 --- a/Presence.Desktop/DI/ServiceCollectionExtensions.cs +++ b/Presence.Desktop/DI/ServiceCollectionExtensions.cs @@ -21,7 +21,20 @@ namespace Presence.Desktop.DI .AddDbContext() .AddSingleton() .AddTransient() + .AddSingleton() + .AddTransient() .AddTransient(); } + + public static void AddPresenceService(this IServiceCollection collection) + { + collection + .AddDbContext() + .AddSingleton() + .AddTransient() + .AddSingleton() + .AddTransient() + .AddTransient(); + } } } diff --git a/Presence.Desktop/Models/GroupSubjectPresenter.cs b/Presence.Desktop/Models/GroupSubjectPresenter.cs index d13c008..25f2410 100644 --- a/Presence.Desktop/Models/GroupSubjectPresenter.cs +++ b/Presence.Desktop/Models/GroupSubjectPresenter.cs @@ -3,10 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Data.DAO; +using Presense.Desktop.Models; namespace Presence.Desktop.Models { - internal class GroupSubjectPresenter + public class GroupSubjectPresenter { + public int GroupSubjectId { get; set; } + public int SemesterId { get; set; } + public SemesterPresenter Semester { get; set; } + public GroupPresenter Group { get; set; } + public SubjectPresenter Subject { get; set; } + public List Attendances { get; set; } } } diff --git a/Presence.Desktop/Models/PresencePresenter.cs b/Presence.Desktop/Models/PresencePresenter.cs index cfc968c..0043495 100644 --- a/Presence.Desktop/Models/PresencePresenter.cs +++ b/Presence.Desktop/Models/PresencePresenter.cs @@ -3,10 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Presense.Desktop.Models; namespace Presence.Desktop.Models { - internal class PresencePresenter + public class PresencePresenter { + public int AttendanceId { get; set; } + public DateOnly Date { get; set; } + public string Subject { get; set; } + public string StudentFullName { get; set; } + public string GroupName { get; set; } + public string PresenceType { get; set; } + public int LessonNumber { get; set; } } } diff --git a/Presence.Desktop/Models/SemesterPresenter.cs b/Presence.Desktop/Models/SemesterPresenter.cs index 2cf7e1e..16af4bf 100644 --- a/Presence.Desktop/Models/SemesterPresenter.cs +++ b/Presence.Desktop/Models/SemesterPresenter.cs @@ -6,7 +6,11 @@ using System.Threading.Tasks; namespace Presence.Desktop.Models { - internal class SemesterPresenter + public class SemesterPresenter { + public int SemesterId { get; set; } + public DateTime StartTime { get; set; } + public DateTime EndTime { get; set; } + public List GroupSubjects { get; set; } } } diff --git a/Presence.Desktop/Models/VisitPresenter.cs b/Presence.Desktop/Models/VisitPresenter.cs index 0cf2fa6..726cc87 100644 --- a/Presence.Desktop/Models/VisitPresenter.cs +++ b/Presence.Desktop/Models/VisitPresenter.cs @@ -1,4 +1,5 @@ -using System; +using Data.DAO; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,10 @@ using System.Threading.Tasks; namespace Presence.Desktop.Models { - class VisitPresenter + public class VisitPresenter { + public int VisitId { get; set; } + public string VisitName { get; set; } + public List Attendances { get; set; } } } diff --git a/Presence.Desktop/ViewModels/GroupViewModel.cs b/Presence.Desktop/ViewModels/GroupViewModel.cs index cd337e6..68bdd9b 100644 --- a/Presence.Desktop/ViewModels/GroupViewModel.cs +++ b/Presence.Desktop/ViewModels/GroupViewModel.cs @@ -9,10 +9,8 @@ using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Reactive; -using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; -using System.Windows.Input; namespace Presence.Desktop.ViewModels { @@ -107,10 +105,10 @@ namespace Presence.Desktop.ViewModels private readonly string[] _sortingOptions = new[] { - "Без сортировки", - "Фамилии (по возрастанию)", - "Фамилии (по убыванию)" - }; + "Без сортировки", + "Фамилии (по возрастанию)", + "Фамилии (по убыванию)" + }; public string[] SortingOptions => _sortingOptions; diff --git a/Presence.Desktop/ViewModels/PresenceViewModel.cs b/Presence.Desktop/ViewModels/PresenceViewModel.cs index 8ff3428..9641aa7 100644 --- a/Presence.Desktop/ViewModels/PresenceViewModel.cs +++ b/Presence.Desktop/ViewModels/PresenceViewModel.cs @@ -1,9 +1,126 @@ -using ReactiveUI; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using data.Repository; +using Data.DAO; +using domain.Service; +using domain.UseCase; +using Presence.Desktop.Models; +using Presense.Desktop.Models; +using ReactiveUI; namespace Presence.Desktop.ViewModels; -public class PresenceViewModel : ViewModelBase, IRoutableViewModel +public class PresenceViewModel : ViewModelBase { - public string? UrlPathSegment { get; } - public IScreen HostScreen { get; } + private readonly PresenceService _presenceService; + private readonly IGroupUseCase _groupService; + private ObservableCollection _presences; + private ObservableCollection _groups; + private GroupPresenter? _selectedGroupItem; + private string? _selectedAttendanceType; + + + public ObservableCollection Presences + { + get => _presences; + set => this.RaiseAndSetIfChanged(ref _presences, value); + } + + public ObservableCollection Groups => _groups; + + public GroupPresenter? SelectedGroupItem + { + get => _selectedGroupItem; + set + { + if (_selectedGroupItem != value) + { + _selectedGroupItem = value; + this.RaisePropertyChanged(); + UpdatePresences(); + } + } + } + + public string[] AttendanceTypes { get; } = { "Был", "Не был", "Болеет" }; + + public string? SelectedAttendanceType + { + get => _selectedAttendanceType; + set + { + this.RaiseAndSetIfChanged(ref _selectedAttendanceType, value); + FilterPresences(); + } + } + + public PresenceViewModel(IGroupUseCase groupService, PresenceService presenceService) + { + _groupService = groupService; + _presenceService = presenceService; + _presences = new ObservableCollection(); + _groups = new ObservableCollection(); + + LoadGroups(); + } + + private void LoadGroups() + { + var groups = _groupService.GetGroupsWithStudents(); // Получаем все группы + _groups.Clear(); + + foreach (var group in groups) + { + _groups.Add(new GroupPresenter { GroupId = group.GroupId, GroupName = group.GroupName }); + } + + // Выбираем первую группу по умолчанию + if (_groups.Any()) + { + SelectedGroupItem = _groups.First(); + } + } + + private void UpdatePresences() + { + if (SelectedGroupItem == null) return; + + var PresencesListHere = _presenceService.GetAttendancesRelativeWithGroup(SelectedGroupItem.GroupId); + ObservableCollection convertedList = new ObservableCollection(); + _presences.Clear(); + + foreach (var attendance in PresencesListHere) + { + convertedList.Add(convertToPresencePresenter(attendance)); + } + + Presences = convertedList; + } + + private PresencePresenter convertToPresencePresenter(Attendance attendance) + { + return new PresencePresenter() + { + AttendanceId = attendance.AttendanceId, + StudentFullName = $"{attendance.Student.FirstName} {attendance.Student.LastName} {attendance.Student.Patronymic}", + Subject = attendance.GroupSubject.Subject.SubjectName, + Date = attendance.Date, + GroupName = attendance.Group.GroupName, + LessonNumber = attendance.LessonNumber, + PresenceType = attendance.Visit.VisitName + }; + } + + private void FilterPresences() + { + if (string.IsNullOrEmpty(SelectedAttendanceType)) return; + + var filteredPresences = _presences.Where(a => a.PresenceType == SelectedAttendanceType).ToList(); + _presences.Clear(); + foreach (var attendance in filteredPresences) + { + _presences.Add(attendance); + } + } } \ No newline at end of file diff --git a/Presence.Desktop/Views/GroupView.axaml b/Presence.Desktop/Views/GroupView.axaml index c0590e9..a2d5ad2 100644 --- a/Presence.Desktop/Views/GroupView.axaml +++ b/Presence.Desktop/Views/GroupView.axaml @@ -40,6 +40,10 @@