using StudentEnrollmentContracts.BindingModels; using StudentEnrollmentContracts.BusinessLogicContracts; using StudentEnrollmentDataModels.Models; namespace StudentEnrollmentView { public partial class FormExamPoints : Form { public int? Id { get; set; } public IExamPointsModel ExamPoints { get; } private IExamPointsLogic _logic; public FormExamPoints(IExamPointsLogic logic) { _logic = logic; InitializeComponent(); } private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxFirstExamPoints.Text)) { MessageBox.Show("Заполните баллы за первый экзамен", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBoxSecondExamPoints.Text)) { MessageBox.Show("Заполните баллы за второй экзамен", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { var model = new ExamPointsBindingModel { Id = Id ?? 0, FirstExamPoints = Convert.ToInt32(textBoxFirstExamPoints.Text), SecondExamPoints = Convert.ToInt32(textBoxSecondExamPoints.Text), ThirdExamPoints = Convert.ToInt32(textBoxThirdExamPoints.Text), AddPoints = Convert.ToInt32(textBoxAddPoints.Text), }; var operationResult = _logic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } } }