2025-04-14 08:28:12 +00:00
|
|
|
using System.Linq;
|
2025-04-14 05:39:47 +00:00
|
|
|
using Avalonia;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
|
using demko_term.Models;
|
|
|
|
|
|
|
|
namespace demko_term;
|
|
|
|
|
|
|
|
public partial class CreateApplicantWindow : Window
|
|
|
|
{
|
2025-04-14 08:28:12 +00:00
|
|
|
|
2025-04-14 14:45:48 +00:00
|
|
|
public int code_prew;
|
2025-04-14 08:28:12 +00:00
|
|
|
|
2025-04-14 05:39:47 +00:00
|
|
|
public CreateApplicantWindow()
|
|
|
|
{
|
2025-04-14 08:28:12 +00:00
|
|
|
|
2025-04-14 05:39:47 +00:00
|
|
|
InitializeComponent();
|
2025-04-14 08:28:12 +00:00
|
|
|
using var context = new DemoCourseworkContext();
|
|
|
|
|
2025-04-14 14:45:48 +00:00
|
|
|
code_prew = context.Applicants.Select(a => a.Code).Max();
|
|
|
|
CodeTextBox.Text = (code_prew + 1).ToString();
|
2025-04-14 05:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CreateApplicant_OnClick(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
2025-04-14 08:28:12 +00:00
|
|
|
using var context = new DemoCourseworkContext();
|
2025-04-14 05:39:47 +00:00
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(FirstNameTextBox.Text) ||
|
|
|
|
string.IsNullOrWhiteSpace(LastNameTextBox.Text) ||
|
|
|
|
string.IsNullOrWhiteSpace(PatronymicTextBox.Text) ||
|
|
|
|
DatePicker.SelectedDate == null ||
|
|
|
|
string.IsNullOrWhiteSpace(CodeTextBox.Text) ||
|
|
|
|
string.IsNullOrWhiteSpace(PassportTextBox.Text) ||
|
|
|
|
string.IsNullOrWhiteSpace(AddressTextBox.Text) ||
|
|
|
|
string.IsNullOrWhiteSpace(EmailTextBox.Text) ||
|
|
|
|
string.IsNullOrWhiteSpace(PhoneNumberTextBox.Text))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var newApplicant = new Applicant
|
|
|
|
{
|
|
|
|
Firstname = FirstNameTextBox.Text,
|
|
|
|
Lastname = LastNameTextBox.Text,
|
|
|
|
Patronymic = PatronymicTextBox.Text,
|
|
|
|
Date = DatePicker.SelectedDate?.DateTime,
|
|
|
|
Code = int.Parse(CodeTextBox.Text),
|
|
|
|
Passport = PassportTextBox.Text,
|
|
|
|
Email = EmailTextBox.Text,
|
|
|
|
Phone = PhoneNumberTextBox.Text,
|
|
|
|
Address = AddressTextBox.Text
|
|
|
|
};
|
|
|
|
|
2025-04-14 08:28:12 +00:00
|
|
|
context.Applicants.Add(newApplicant);
|
|
|
|
context.SaveChanges();
|
2025-04-14 05:39:47 +00:00
|
|
|
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|