diff --git a/StudentEnrollment/StudentEnrollmentBusinessLogic/ExamPointsLogic.cs b/StudentEnrollment/StudentEnrollmentBusinessLogic/ExamPointsLogic.cs index a39294b..d2f4c49 100644 --- a/StudentEnrollment/StudentEnrollmentBusinessLogic/ExamPointsLogic.cs +++ b/StudentEnrollment/StudentEnrollmentBusinessLogic/ExamPointsLogic.cs @@ -4,6 +4,7 @@ using StudentEnrollmentContracts.BusinessLogicContracts; using StudentEnrollmentContracts.SearchModels; using StudentEnrollmentContracts.StorageContracts; using StudentEnrollmentContracts.ViewModels; +using StudentEnrollmentDataModels.Models; namespace StudentEnrollmentBusinessLogic { @@ -56,6 +57,22 @@ namespace StudentEnrollmentBusinessLogic } return true; } + + public IExamPointsModel Create(ExamPointsBindingModel model, bool returnTypeIsModel) + { + if (returnTypeIsModel) + { + CheckModel(model); + if (_examPointsStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return null; + } + var list = _examPointsStorage.GetFullList(); + return list[list.Count - 1]; + } + return null; + } public bool Update(ExamPointsBindingModel model) { CheckModel(model); diff --git a/StudentEnrollment/StudentEnrollmentContracts/BusinessLogicContracts/IExamPointsLogic.cs b/StudentEnrollment/StudentEnrollmentContracts/BusinessLogicContracts/IExamPointsLogic.cs index 7743344..ca512e8 100644 --- a/StudentEnrollment/StudentEnrollmentContracts/BusinessLogicContracts/IExamPointsLogic.cs +++ b/StudentEnrollment/StudentEnrollmentContracts/BusinessLogicContracts/IExamPointsLogic.cs @@ -1,6 +1,7 @@ using StudentEnrollmentContracts.BindingModels; using StudentEnrollmentContracts.SearchModels; using StudentEnrollmentContracts.ViewModels; +using StudentEnrollmentDataModels.Models; namespace StudentEnrollmentContracts.BusinessLogicContracts { @@ -9,6 +10,7 @@ namespace StudentEnrollmentContracts.BusinessLogicContracts List? ReadList(ExamPointsSearchModel? model); ExamPointsViewModel? ReadElement(ExamPointsSearchModel model); bool Create(ExamPointsBindingModel model); + IExamPointsModel Create(ExamPointsBindingModel model, bool returnTypeIsModel); bool Update(ExamPointsBindingModel model); bool Delete(ExamPointsBindingModel model); } diff --git a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs index c05ceff..965ab6a 100644 --- a/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs +++ b/StudentEnrollment/StudentEnrollmentDatabaseImplement/Models/Student.cs @@ -44,6 +44,11 @@ namespace StudentEnrollmentDatabaseImplement.Models { return null; } + var test = model.StudentCourse.Select(x => new StudentCourse + { + Course = context.course.First(y => y.course_id == x.Key) + } + ).ToList(); return new Student() { student_id = model.Id, @@ -57,6 +62,7 @@ namespace StudentEnrollmentDatabaseImplement.Models Course = context.course.First(y => y.course_id == x.Key) } ).ToList(), + ExamPoints = context.exampoints.First(x => x.exampoints_id == model.ExamPointsId), }; } public void Update(StudentBindingModel model) diff --git a/StudentEnrollment/StudentEnrollmentView/FormExamPoints.cs b/StudentEnrollment/StudentEnrollmentView/FormExamPoints.cs index b7140f0..49c0076 100644 --- a/StudentEnrollment/StudentEnrollmentView/FormExamPoints.cs +++ b/StudentEnrollment/StudentEnrollmentView/FormExamPoints.cs @@ -10,7 +10,7 @@ namespace StudentEnrollmentView public partial class FormExamPoints : Form { public int? Id { get; set; } - public IExamPointsModel ExamPoints { get; } + public IExamPointsModel ExamPoints { get; set; } private IExamPointsLogic _logic; public FormExamPoints(IExamPointsLogic logic) { @@ -46,13 +46,14 @@ namespace StudentEnrollmentView AddPoints = textBoxAddPoints.Text != string.Empty ? Convert.ToInt32(textBoxAddPoints.Text) : 0, Summary = CalcSum(), }; - var operationResult = _logic.Create(model); - if (!operationResult) + var operationResult = _logic.Create(model, true); + if (operationResult == null) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; + ExamPoints = operationResult; Close(); } catch (Exception ex) diff --git a/StudentEnrollment/StudentEnrollmentView/FormMain.Designer.cs b/StudentEnrollment/StudentEnrollmentView/FormMain.Designer.cs index 0880485..9c0adad 100644 --- a/StudentEnrollment/StudentEnrollmentView/FormMain.Designer.cs +++ b/StudentEnrollment/StudentEnrollmentView/FormMain.Designer.cs @@ -35,13 +35,13 @@ студентыToolStripMenuItem = new ToolStripMenuItem(); buttonAdd = new Button(); groupBox1 = new GroupBox(); - labelAdd = new Label(); - labelGet = new Label(); - buttonGet = new Button(); - labelUpdate = new Label(); - buttonUpdate = new Button(); labelDelete = new Label(); buttonDelete = new Button(); + labelUpdate = new Label(); + buttonUpdate = new Button(); + labelGet = new Label(); + buttonGet = new Button(); + labelAdd = new Label(); menuStrip1.SuspendLayout(); groupBox1.SuspendLayout(); SuspendLayout(); @@ -112,38 +112,29 @@ groupBox1.TabStop = false; groupBox1.Text = "Тесты:"; // - // labelAdd + // labelDelete // - labelAdd.AutoSize = true; - labelAdd.Location = new Point(314, 44); - labelAdd.Name = "labelAdd"; - labelAdd.Size = new Size(31, 15); - labelAdd.TabIndex = 4; - labelAdd.Text = "0 мс"; + labelDelete.AutoSize = true; + labelDelete.Location = new Point(290, 235); + labelDelete.Name = "labelDelete"; + labelDelete.Size = new Size(31, 15); + labelDelete.TabIndex = 10; + labelDelete.Text = "0 мс"; // - // labelGet + // buttonDelete // - labelGet.AutoSize = true; - labelGet.Location = new Point(314, 106); - labelGet.Name = "labelGet"; - labelGet.Size = new Size(31, 15); - labelGet.TabIndex = 6; - labelGet.Text = "0 мс"; - // - // buttonGet - // - buttonGet.Location = new Point(17, 94); - buttonGet.Name = "buttonGet"; - buttonGet.Size = new Size(171, 39); - buttonGet.TabIndex = 5; - buttonGet.Text = "Получение 1000 строк"; - buttonGet.UseVisualStyleBackColor = true; - buttonGet.Click += buttonGet_Click; + buttonDelete.Location = new Point(17, 223); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(171, 39); + buttonDelete.TabIndex = 9; + buttonDelete.Text = "Удаление 1000 строк"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; // // labelUpdate // labelUpdate.AutoSize = true; - labelUpdate.Location = new Point(314, 171); + labelUpdate.Location = new Point(290, 171); labelUpdate.Name = "labelUpdate"; labelUpdate.Size = new Size(31, 15); labelUpdate.TabIndex = 8; @@ -159,24 +150,33 @@ buttonUpdate.UseVisualStyleBackColor = true; buttonUpdate.Click += buttonUpdate_Click; // - // labelDelete + // labelGet // - labelDelete.AutoSize = true; - labelDelete.Location = new Point(314, 235); - labelDelete.Name = "labelDelete"; - labelDelete.Size = new Size(31, 15); - labelDelete.TabIndex = 10; - labelDelete.Text = "0 мс"; + labelGet.AutoSize = true; + labelGet.Location = new Point(290, 106); + labelGet.Name = "labelGet"; + labelGet.Size = new Size(31, 15); + labelGet.TabIndex = 6; + labelGet.Text = "0 мс"; // - // buttonDelete + // buttonGet // - buttonDelete.Location = new Point(17, 223); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(171, 39); - buttonDelete.TabIndex = 9; - buttonDelete.Text = "Удаление 1000 строк"; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; + buttonGet.Location = new Point(17, 94); + buttonGet.Name = "buttonGet"; + buttonGet.Size = new Size(171, 39); + buttonGet.TabIndex = 5; + buttonGet.Text = "Получение 1000 строк"; + buttonGet.UseVisualStyleBackColor = true; + buttonGet.Click += buttonGet_Click; + // + // labelAdd + // + labelAdd.AutoSize = true; + labelAdd.Location = new Point(290, 44); + labelAdd.Name = "labelAdd"; + labelAdd.Size = new Size(31, 15); + labelAdd.TabIndex = 4; + labelAdd.Text = "0 мс"; // // FormMain // diff --git a/StudentEnrollment/StudentEnrollmentView/FormMain.cs b/StudentEnrollment/StudentEnrollmentView/FormMain.cs index 824b0eb..020edc3 100644 --- a/StudentEnrollment/StudentEnrollmentView/FormMain.cs +++ b/StudentEnrollment/StudentEnrollmentView/FormMain.cs @@ -74,12 +74,13 @@ namespace StudentEnrollmentView var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic)); if (service is IFacultyLogic logic) { + List ids = logic.ReadList(null).Select(x => x.Id).ToList(); DateTime startTime = DateTime.Now; - for (int i = 0; i < 1000; i++) + for (int i = 0; i < ids.Count; i++) { logic.Update(new FacultyBindingModel { - Id = i, + Id = ids[i], FacultyName = "новый факультет " + i, }); } @@ -93,12 +94,13 @@ namespace StudentEnrollmentView var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic)); if (service is IFacultyLogic logic) { + List ids = logic.ReadList(null).Select(x => x.Id).ToList(); DateTime startTime = DateTime.Now; - for (int i = 0; i < 1000; i++) + for (int i = 0; i < ids.Count; i++) { logic.Delete(new FacultyBindingModel { - Id = i, + Id = ids[i], }); } DateTime endTime = DateTime.Now; diff --git a/StudentEnrollment/StudentEnrollmentView/FormStudentCourse.cs b/StudentEnrollment/StudentEnrollmentView/FormStudentCourse.cs index 024e7bd..593c8e6 100644 --- a/StudentEnrollment/StudentEnrollmentView/FormStudentCourse.cs +++ b/StudentEnrollment/StudentEnrollmentView/FormStudentCourse.cs @@ -42,8 +42,8 @@ namespace StudentEnrollmentView _list = logic.ReadList(null); if (_list != null) { - comboBoxCourse.DisplayMember = "CourseName"; - comboBoxCourse.ValueMember = "Id"; + comboBoxCourse.DisplayMember = "name"; + comboBoxCourse.ValueMember = "course_id"; comboBoxCourse.DataSource = _list; comboBoxCourse.SelectedItem = null; }