51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
|
using Avalonia;
|
||
|
using Avalonia.Controls;
|
||
|
using Avalonia.Interactivity;
|
||
|
using Avalonia.Markup.Xaml;
|
||
|
using demko_term.Models;
|
||
|
|
||
|
namespace demko_term;
|
||
|
|
||
|
public partial class CreateApplicantWindow : Window
|
||
|
{
|
||
|
public CreateApplicantWindow()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
public void CreateApplicant_OnClick(object? sender, RoutedEventArgs e)
|
||
|
{
|
||
|
using var ctx = new DemoCourseworkContext();
|
||
|
|
||
|
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
|
||
|
};
|
||
|
|
||
|
ctx.Applicants.Add(newApplicant);
|
||
|
ctx.SaveChanges();
|
||
|
|
||
|
Close();
|
||
|
}
|
||
|
}
|