fix issue with creating student entity, full lab4

This commit is contained in:
DavidMakarov 2024-05-14 20:43:40 +04:00
parent fba63e61f6
commit fb04543cd0
7 changed files with 82 additions and 54 deletions

View File

@ -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);

View File

@ -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<ExamPointsViewModel>? 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);
}

View File

@ -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)

View File

@ -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)

View File

@ -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
//

View File

@ -74,12 +74,13 @@ namespace StudentEnrollmentView
var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic));
if (service is IFacultyLogic logic)
{
List<int> 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<int> 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;

View File

@ -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;
}