2024-11-07 13:41:24 +04:00
|
|
|
|
using Lab3.Database.DTO;
|
|
|
|
|
using Lab3.Database.Models;
|
|
|
|
|
using Lab3.Database.Repository.Interfaces;
|
2024-11-06 23:06:47 +04:00
|
|
|
|
|
|
|
|
|
namespace Lab3.Forms
|
|
|
|
|
{
|
|
|
|
|
public partial class CreateForm : Form
|
|
|
|
|
{
|
2024-11-07 13:41:24 +04:00
|
|
|
|
private readonly IStudentRepository _studentRepository;
|
|
|
|
|
|
|
|
|
|
private readonly IEducationFormRepository _educationFormRepository;
|
|
|
|
|
|
|
|
|
|
private readonly Guid? _updatedStudentGuid = null;
|
|
|
|
|
|
|
|
|
|
public CreateForm(
|
|
|
|
|
IStudentRepository studentRepository,
|
|
|
|
|
IEducationFormRepository educationFormRepository,
|
|
|
|
|
Guid? updatedStudentGuid)
|
2024-11-06 23:06:47 +04:00
|
|
|
|
{
|
2024-11-07 13:41:24 +04:00
|
|
|
|
_studentRepository = studentRepository;
|
|
|
|
|
_educationFormRepository = educationFormRepository;
|
|
|
|
|
|
|
|
|
|
_updatedStudentGuid = updatedStudentGuid;
|
|
|
|
|
|
2024-11-06 23:06:47 +04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2024-11-06 23:20:09 +04:00
|
|
|
|
|
2024-11-07 13:41:24 +04:00
|
|
|
|
private async void CreateForm_LoadAsync(object sender, EventArgs e)
|
2024-11-06 23:20:09 +04:00
|
|
|
|
{
|
2024-11-07 13:41:24 +04:00
|
|
|
|
FormSelector.Fill(await _educationFormRepository.Get());
|
|
|
|
|
StartEducationDataPicker.DateStart = DateTime.Now.AddYears(-6);
|
|
|
|
|
StartEducationDataPicker.DateEnd = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void ButtonSave_ClickAsync(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(NameTextBox.Text)
|
|
|
|
|
|| string.IsNullOrEmpty(FormSelector.ComboBoxSelectedValue))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudentDTO student = new()
|
|
|
|
|
{
|
|
|
|
|
Id = _updatedStudentGuid ?? Guid.NewGuid(),
|
|
|
|
|
Name = NameTextBox.Text,
|
|
|
|
|
StartEducation = StartEducationDataPicker.Value,
|
|
|
|
|
EducationForm = FormSelector.ComboBoxSelectedValue,
|
|
|
|
|
StudentSessions = [
|
|
|
|
|
new(){
|
|
|
|
|
Score = session1Score.Value,
|
|
|
|
|
Number = 1,
|
|
|
|
|
},
|
|
|
|
|
new(){
|
|
|
|
|
Score = session2Score.Value,
|
|
|
|
|
Number = 2,
|
|
|
|
|
},
|
|
|
|
|
new(){
|
|
|
|
|
Score = session3Score.Value,
|
|
|
|
|
Number = 3,
|
|
|
|
|
},
|
|
|
|
|
new(){
|
|
|
|
|
Score = session4Score.Value,
|
|
|
|
|
Number = 4,
|
|
|
|
|
},
|
|
|
|
|
new(){
|
|
|
|
|
Score = session5Score.Value,
|
|
|
|
|
Number = 5,
|
|
|
|
|
},
|
|
|
|
|
new(){
|
|
|
|
|
Score = session6Score.Value,
|
|
|
|
|
Number = 6,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
2024-11-06 23:20:09 +04:00
|
|
|
|
|
2024-11-07 13:41:24 +04:00
|
|
|
|
if (_updatedStudentGuid != null)
|
|
|
|
|
{
|
|
|
|
|
await _studentRepository.UpdateAsync(student);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _studentRepository.CreateAsync(student);
|
|
|
|
|
}
|
2024-11-06 23:20:09 +04:00
|
|
|
|
}
|
2024-11-06 23:06:47 +04:00
|
|
|
|
}
|
|
|
|
|
}
|