From 09a8bc1857afe257ee27c9c6e68e18e20054d99f Mon Sep 17 00:00:00 2001 From: bekodeg Date: Thu, 7 Nov 2024 14:04:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B8=D0=BB=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implementations/StudentRepository.cs | 8 ++++++- .../Interfaces/IStudentRepository.cs | 10 ++++---- Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs | 23 +++++++++++++++++++ Cop.Borovkov.Var3/Lab3/Program.cs | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs index 8f0d2f0..0b13144 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Implementations/StudentRepository.cs @@ -39,7 +39,13 @@ namespace Lab3.Database.Repository.Implementations .Take(limit) .ToListAsync()); - public Task GetAsync(Guid id) => throw new NotImplementedException(); + public async Task GetAsync(Guid id) + { + return _mapper.Map( + await _context.Students + .Include(s => s.StudentSessions) + .FirstOrDefaultAsync()); + } public async Task UpdateAsync(StudentDTO studentDTO) { diff --git a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs index 6561dc0..4b1873f 100644 --- a/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs +++ b/Cop.Borovkov.Var3/Lab3.Database/Repository/Interfaces/IStudentRepository.cs @@ -4,14 +4,14 @@ namespace Lab3.Database.Repository.Interfaces { public interface IStudentRepository { - public Task> GetAsync(int limit = 10000, int offset = 0); + Task> GetAsync(int limit = 10000, int offset = 0); - public Task GetAsync(Guid id); + Task GetAsync(Guid id); - public Task UpdateAsync(StudentDTO studentDTO); + Task UpdateAsync(StudentDTO studentDTO); - public Task DeleteAsync(Guid id); + Task DeleteAsync(Guid id); - public Task CreateAsync(StudentDTO studentDTO); + Task CreateAsync(StudentDTO studentDTO); } } diff --git a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs index e9a5049..9a6cb6f 100644 --- a/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs +++ b/Cop.Borovkov.Var3/Lab3/Forms/CreateForm.cs @@ -30,6 +30,29 @@ namespace Lab3.Forms FormSelector.Fill(await _educationFormRepository.Get()); StartEducationDataPicker.DateStart = DateTime.Now.AddYears(-6); StartEducationDataPicker.DateEnd = DateTime.Now; + + if (_updatedStudentGuid == null) + { + return; + } + var student = await _studentRepository.GetAsync(_updatedStudentGuid.Value); + + NameTextBox.Text = student.Name; + StartEducationDataPicker.Value = student.StartEducation; + FormSelector.ComboBoxSelectedValue = student.EducationForm; + + session1Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 1)?.Score ?? decimal.Zero; + session2Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 2)?.Score ?? decimal.Zero; + session3Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 3)?.Score ?? decimal.Zero; + session4Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 4)?.Score ?? decimal.Zero; + session5Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 5)?.Score ?? decimal.Zero; + session6Score.Value = student.StudentSessions + .FirstOrDefault(s => s.Number == 6)?.Score ?? decimal.Zero; } private async void ButtonSave_ClickAsync(object sender, EventArgs e) diff --git a/Cop.Borovkov.Var3/Lab3/Program.cs b/Cop.Borovkov.Var3/Lab3/Program.cs index b98c3b6..2ac9d73 100644 --- a/Cop.Borovkov.Var3/Lab3/Program.cs +++ b/Cop.Borovkov.Var3/Lab3/Program.cs @@ -21,7 +21,7 @@ namespace Lab3 var app = CreateHostBuilder().Build(); - Application.Run(app.Services.GetRequiredService>()(null)); + Application.Run(app.Services.GetRequiredService()); } static IHostBuilder CreateHostBuilder()