fix issue with creating student entity, full lab4
This commit is contained in:
parent
fba63e61f6
commit
fb04543cd0
@ -4,6 +4,7 @@ using StudentEnrollmentContracts.BusinessLogicContracts;
|
|||||||
using StudentEnrollmentContracts.SearchModels;
|
using StudentEnrollmentContracts.SearchModels;
|
||||||
using StudentEnrollmentContracts.StorageContracts;
|
using StudentEnrollmentContracts.StorageContracts;
|
||||||
using StudentEnrollmentContracts.ViewModels;
|
using StudentEnrollmentContracts.ViewModels;
|
||||||
|
using StudentEnrollmentDataModels.Models;
|
||||||
|
|
||||||
namespace StudentEnrollmentBusinessLogic
|
namespace StudentEnrollmentBusinessLogic
|
||||||
{
|
{
|
||||||
@ -56,6 +57,22 @@ namespace StudentEnrollmentBusinessLogic
|
|||||||
}
|
}
|
||||||
return true;
|
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)
|
public bool Update(ExamPointsBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using StudentEnrollmentContracts.BindingModels;
|
using StudentEnrollmentContracts.BindingModels;
|
||||||
using StudentEnrollmentContracts.SearchModels;
|
using StudentEnrollmentContracts.SearchModels;
|
||||||
using StudentEnrollmentContracts.ViewModels;
|
using StudentEnrollmentContracts.ViewModels;
|
||||||
|
using StudentEnrollmentDataModels.Models;
|
||||||
|
|
||||||
namespace StudentEnrollmentContracts.BusinessLogicContracts
|
namespace StudentEnrollmentContracts.BusinessLogicContracts
|
||||||
{
|
{
|
||||||
@ -9,6 +10,7 @@ namespace StudentEnrollmentContracts.BusinessLogicContracts
|
|||||||
List<ExamPointsViewModel>? ReadList(ExamPointsSearchModel? model);
|
List<ExamPointsViewModel>? ReadList(ExamPointsSearchModel? model);
|
||||||
ExamPointsViewModel? ReadElement(ExamPointsSearchModel model);
|
ExamPointsViewModel? ReadElement(ExamPointsSearchModel model);
|
||||||
bool Create(ExamPointsBindingModel model);
|
bool Create(ExamPointsBindingModel model);
|
||||||
|
IExamPointsModel Create(ExamPointsBindingModel model, bool returnTypeIsModel);
|
||||||
bool Update(ExamPointsBindingModel model);
|
bool Update(ExamPointsBindingModel model);
|
||||||
bool Delete(ExamPointsBindingModel model);
|
bool Delete(ExamPointsBindingModel model);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,11 @@ namespace StudentEnrollmentDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
var test = model.StudentCourse.Select(x => new StudentCourse
|
||||||
|
{
|
||||||
|
Course = context.course.First(y => y.course_id == x.Key)
|
||||||
|
}
|
||||||
|
).ToList();
|
||||||
return new Student()
|
return new Student()
|
||||||
{
|
{
|
||||||
student_id = model.Id,
|
student_id = model.Id,
|
||||||
@ -57,6 +62,7 @@ namespace StudentEnrollmentDatabaseImplement.Models
|
|||||||
Course = context.course.First(y => y.course_id == x.Key)
|
Course = context.course.First(y => y.course_id == x.Key)
|
||||||
}
|
}
|
||||||
).ToList(),
|
).ToList(),
|
||||||
|
ExamPoints = context.exampoints.First(x => x.exampoints_id == model.ExamPointsId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(StudentBindingModel model)
|
public void Update(StudentBindingModel model)
|
||||||
|
@ -10,7 +10,7 @@ namespace StudentEnrollmentView
|
|||||||
public partial class FormExamPoints : Form
|
public partial class FormExamPoints : Form
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public IExamPointsModel ExamPoints { get; }
|
public IExamPointsModel ExamPoints { get; set; }
|
||||||
private IExamPointsLogic _logic;
|
private IExamPointsLogic _logic;
|
||||||
public FormExamPoints(IExamPointsLogic logic)
|
public FormExamPoints(IExamPointsLogic logic)
|
||||||
{
|
{
|
||||||
@ -46,13 +46,14 @@ namespace StudentEnrollmentView
|
|||||||
AddPoints = textBoxAddPoints.Text != string.Empty ? Convert.ToInt32(textBoxAddPoints.Text) : 0,
|
AddPoints = textBoxAddPoints.Text != string.Empty ? Convert.ToInt32(textBoxAddPoints.Text) : 0,
|
||||||
Summary = CalcSum(),
|
Summary = CalcSum(),
|
||||||
};
|
};
|
||||||
var operationResult = _logic.Create(model);
|
var operationResult = _logic.Create(model, true);
|
||||||
if (!operationResult)
|
if (operationResult == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
|
ExamPoints = operationResult;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -35,13 +35,13 @@
|
|||||||
студентыToolStripMenuItem = new ToolStripMenuItem();
|
студентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
buttonAdd = new Button();
|
buttonAdd = new Button();
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
labelAdd = new Label();
|
|
||||||
labelGet = new Label();
|
|
||||||
buttonGet = new Button();
|
|
||||||
labelUpdate = new Label();
|
|
||||||
buttonUpdate = new Button();
|
|
||||||
labelDelete = new Label();
|
labelDelete = new Label();
|
||||||
buttonDelete = new Button();
|
buttonDelete = new Button();
|
||||||
|
labelUpdate = new Label();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
labelGet = new Label();
|
||||||
|
buttonGet = new Button();
|
||||||
|
labelAdd = new Label();
|
||||||
menuStrip1.SuspendLayout();
|
menuStrip1.SuspendLayout();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -112,38 +112,29 @@
|
|||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Тесты:";
|
groupBox1.Text = "Тесты:";
|
||||||
//
|
//
|
||||||
// labelAdd
|
// labelDelete
|
||||||
//
|
//
|
||||||
labelAdd.AutoSize = true;
|
labelDelete.AutoSize = true;
|
||||||
labelAdd.Location = new Point(314, 44);
|
labelDelete.Location = new Point(290, 235);
|
||||||
labelAdd.Name = "labelAdd";
|
labelDelete.Name = "labelDelete";
|
||||||
labelAdd.Size = new Size(31, 15);
|
labelDelete.Size = new Size(31, 15);
|
||||||
labelAdd.TabIndex = 4;
|
labelDelete.TabIndex = 10;
|
||||||
labelAdd.Text = "0 мс";
|
labelDelete.Text = "0 мс";
|
||||||
//
|
//
|
||||||
// labelGet
|
// buttonDelete
|
||||||
//
|
//
|
||||||
labelGet.AutoSize = true;
|
buttonDelete.Location = new Point(17, 223);
|
||||||
labelGet.Location = new Point(314, 106);
|
buttonDelete.Name = "buttonDelete";
|
||||||
labelGet.Name = "labelGet";
|
buttonDelete.Size = new Size(171, 39);
|
||||||
labelGet.Size = new Size(31, 15);
|
buttonDelete.TabIndex = 9;
|
||||||
labelGet.TabIndex = 6;
|
buttonDelete.Text = "Удаление 1000 строк";
|
||||||
labelGet.Text = "0 мс";
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
//
|
buttonDelete.Click += buttonDelete_Click;
|
||||||
// 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;
|
|
||||||
//
|
//
|
||||||
// labelUpdate
|
// labelUpdate
|
||||||
//
|
//
|
||||||
labelUpdate.AutoSize = true;
|
labelUpdate.AutoSize = true;
|
||||||
labelUpdate.Location = new Point(314, 171);
|
labelUpdate.Location = new Point(290, 171);
|
||||||
labelUpdate.Name = "labelUpdate";
|
labelUpdate.Name = "labelUpdate";
|
||||||
labelUpdate.Size = new Size(31, 15);
|
labelUpdate.Size = new Size(31, 15);
|
||||||
labelUpdate.TabIndex = 8;
|
labelUpdate.TabIndex = 8;
|
||||||
@ -159,24 +150,33 @@
|
|||||||
buttonUpdate.UseVisualStyleBackColor = true;
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
buttonUpdate.Click += buttonUpdate_Click;
|
buttonUpdate.Click += buttonUpdate_Click;
|
||||||
//
|
//
|
||||||
// labelDelete
|
// labelGet
|
||||||
//
|
//
|
||||||
labelDelete.AutoSize = true;
|
labelGet.AutoSize = true;
|
||||||
labelDelete.Location = new Point(314, 235);
|
labelGet.Location = new Point(290, 106);
|
||||||
labelDelete.Name = "labelDelete";
|
labelGet.Name = "labelGet";
|
||||||
labelDelete.Size = new Size(31, 15);
|
labelGet.Size = new Size(31, 15);
|
||||||
labelDelete.TabIndex = 10;
|
labelGet.TabIndex = 6;
|
||||||
labelDelete.Text = "0 мс";
|
labelGet.Text = "0 мс";
|
||||||
//
|
//
|
||||||
// buttonDelete
|
// buttonGet
|
||||||
//
|
//
|
||||||
buttonDelete.Location = new Point(17, 223);
|
buttonGet.Location = new Point(17, 94);
|
||||||
buttonDelete.Name = "buttonDelete";
|
buttonGet.Name = "buttonGet";
|
||||||
buttonDelete.Size = new Size(171, 39);
|
buttonGet.Size = new Size(171, 39);
|
||||||
buttonDelete.TabIndex = 9;
|
buttonGet.TabIndex = 5;
|
||||||
buttonDelete.Text = "Удаление 1000 строк";
|
buttonGet.Text = "Получение 1000 строк";
|
||||||
buttonDelete.UseVisualStyleBackColor = true;
|
buttonGet.UseVisualStyleBackColor = true;
|
||||||
buttonDelete.Click += buttonDelete_Click;
|
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
|
// FormMain
|
||||||
//
|
//
|
||||||
|
@ -74,12 +74,13 @@ namespace StudentEnrollmentView
|
|||||||
var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic));
|
var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic));
|
||||||
if (service is IFacultyLogic logic)
|
if (service is IFacultyLogic logic)
|
||||||
{
|
{
|
||||||
|
List<int> ids = logic.ReadList(null).Select(x => x.Id).ToList();
|
||||||
DateTime startTime = DateTime.Now;
|
DateTime startTime = DateTime.Now;
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < ids.Count; i++)
|
||||||
{
|
{
|
||||||
logic.Update(new FacultyBindingModel
|
logic.Update(new FacultyBindingModel
|
||||||
{
|
{
|
||||||
Id = i,
|
Id = ids[i],
|
||||||
FacultyName = "новый факультет " + i,
|
FacultyName = "новый факультет " + i,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -93,12 +94,13 @@ namespace StudentEnrollmentView
|
|||||||
var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic));
|
var service = Program.ServiceProvider?.GetService(typeof(IFacultyLogic));
|
||||||
if (service is IFacultyLogic logic)
|
if (service is IFacultyLogic logic)
|
||||||
{
|
{
|
||||||
|
List<int> ids = logic.ReadList(null).Select(x => x.Id).ToList();
|
||||||
DateTime startTime = DateTime.Now;
|
DateTime startTime = DateTime.Now;
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < ids.Count; i++)
|
||||||
{
|
{
|
||||||
logic.Delete(new FacultyBindingModel
|
logic.Delete(new FacultyBindingModel
|
||||||
{
|
{
|
||||||
Id = i,
|
Id = ids[i],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
DateTime endTime = DateTime.Now;
|
DateTime endTime = DateTime.Now;
|
||||||
|
@ -42,8 +42,8 @@ namespace StudentEnrollmentView
|
|||||||
_list = logic.ReadList(null);
|
_list = logic.ReadList(null);
|
||||||
if (_list != null)
|
if (_list != null)
|
||||||
{
|
{
|
||||||
comboBoxCourse.DisplayMember = "CourseName";
|
comboBoxCourse.DisplayMember = "name";
|
||||||
comboBoxCourse.ValueMember = "Id";
|
comboBoxCourse.ValueMember = "course_id";
|
||||||
comboBoxCourse.DataSource = _list;
|
comboBoxCourse.DataSource = _list;
|
||||||
comboBoxCourse.SelectedItem = null;
|
comboBoxCourse.SelectedItem = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user