Добил добавление и изменение

This commit is contained in:
bekodeg 2024-11-07 14:04:13 +04:00
parent 2c0e6b13f5
commit 09a8bc1857
4 changed files with 36 additions and 7 deletions

View File

@ -39,7 +39,13 @@ namespace Lab3.Database.Repository.Implementations
.Take(limit) .Take(limit)
.ToListAsync()); .ToListAsync());
public Task<StudentDTO> GetAsync(Guid id) => throw new NotImplementedException(); public async Task<StudentDTO?> GetAsync(Guid id)
{
return _mapper.Map<StudentDTO>(
await _context.Students
.Include(s => s.StudentSessions)
.FirstOrDefaultAsync());
}
public async Task<StudentDTO?> UpdateAsync(StudentDTO studentDTO) public async Task<StudentDTO?> UpdateAsync(StudentDTO studentDTO)
{ {

View File

@ -4,14 +4,14 @@ namespace Lab3.Database.Repository.Interfaces
{ {
public interface IStudentRepository public interface IStudentRepository
{ {
public Task<List<StudentDTO>> GetAsync(int limit = 10000, int offset = 0); Task<List<StudentDTO>> GetAsync(int limit = 10000, int offset = 0);
public Task<StudentDTO> GetAsync(Guid id); Task<StudentDTO?> GetAsync(Guid id);
public Task<StudentDTO?> UpdateAsync(StudentDTO studentDTO); Task<StudentDTO?> UpdateAsync(StudentDTO studentDTO);
public Task<StudentDTO> DeleteAsync(Guid id); Task<StudentDTO> DeleteAsync(Guid id);
public Task<StudentDTO> CreateAsync(StudentDTO studentDTO); Task<StudentDTO> CreateAsync(StudentDTO studentDTO);
} }
} }

View File

@ -30,6 +30,29 @@ namespace Lab3.Forms
FormSelector.Fill(await _educationFormRepository.Get()); FormSelector.Fill(await _educationFormRepository.Get());
StartEducationDataPicker.DateStart = DateTime.Now.AddYears(-6); StartEducationDataPicker.DateStart = DateTime.Now.AddYears(-6);
StartEducationDataPicker.DateEnd = DateTime.Now; 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) private async void ButtonSave_ClickAsync(object sender, EventArgs e)

View File

@ -21,7 +21,7 @@ namespace Lab3
var app = CreateHostBuilder().Build(); var app = CreateHostBuilder().Build();
Application.Run(app.Services.GetRequiredService<Func<Guid?, CreateForm>>()(null)); Application.Run(app.Services.GetRequiredService<MainForm>());
} }
static IHostBuilder CreateHostBuilder() static IHostBuilder CreateHostBuilder()