Готовая 2 лаб
This commit is contained in:
parent
4695c8d1c8
commit
ad006f8af0
@ -9,7 +9,18 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Npgsql" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
<PackageReference Include="Unity" Version="5.11.10" />
|
<PackageReference Include="Unity" Version="5.11.10" />
|
||||||
|
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -27,4 +38,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Academic_Performance.Entities.Enums
|
namespace Academic_Performance.Entities.Enums
|
||||||
{ [Flags]
|
{ [Flags]
|
||||||
public enum Group
|
public enum Groupp
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
First = 1,
|
First = 1,
|
@ -13,8 +13,8 @@ namespace Academic_Performance.Entities
|
|||||||
public int StudentId { get; private set; }
|
public int StudentId { get; private set; }
|
||||||
public int StatmentTeacherId { get; private set; }
|
public int StatmentTeacherId { get; private set; }
|
||||||
public int StatmentSubjectId { get; private set; }
|
public int StatmentSubjectId { get; private set; }
|
||||||
public int Value { get; private set; }
|
public string Value { get; private set; } = string.Empty;
|
||||||
public static Mark CreateElement(int id, int studentId, int statmentSubjectId, int statmentTeacherId, int value)
|
public static Mark CreateElement(int id, int studentId, int statmentSubjectId, int statmentTeacherId,string value)
|
||||||
{
|
{
|
||||||
return new Mark
|
return new Mark
|
||||||
{
|
{
|
||||||
|
@ -10,17 +10,17 @@ namespace Academic_Performance.Entities
|
|||||||
{
|
{
|
||||||
public class Statement
|
public class Statement
|
||||||
{ public int Id { get; private set; }
|
{ public int Id { get; private set; }
|
||||||
public int SubjecttId { get; private set; }
|
public int SubjectId { get; private set; }
|
||||||
public int TeacherId{ get; private set; }
|
public int TeacherId{ get; private set; }
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
public IEnumerable<Mark> Mark{ get; private set; } = [];
|
public IEnumerable<Mark> Mark{ get; private set; } = [];
|
||||||
public static Statement CreateOperation(int id, int subjecttId, int teacherId, IEnumerable<Mark> mark)
|
public static Statement CreateOperation(int id, int subjectId, int teacherId, IEnumerable<Mark> mark)
|
||||||
{return new Statement
|
{return new Statement
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
SubjecttId = subjecttId,
|
SubjectId = subjectId,
|
||||||
TeacherId = teacherId,
|
TeacherId = teacherId,
|
||||||
Date = DateTime.Now,
|
|
||||||
Mark = mark
|
Mark = mark
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -10,17 +10,17 @@ namespace Academic_Performance.Entities
|
|||||||
public class Student
|
public class Student
|
||||||
{
|
{
|
||||||
public int Id{ get; private set; }
|
public int Id{ get; private set; }
|
||||||
public Group? Group { get; private set; }
|
public Groupp? Groupp { get; private set; }
|
||||||
public string Name { get; private set; } = string.Empty;
|
public string Name { get; private set; } = string.Empty;
|
||||||
public string Flow { get; private set; } = string.Empty;
|
public string Flow { get; private set; } = string.Empty;
|
||||||
public static Student CreateEntity(int id, string name,string flow, Group group)
|
public static Student CreateEntity(int id, string name,string flow, Groupp groupp)
|
||||||
{
|
{
|
||||||
return new Student
|
return new Student
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Name = name,
|
Name = name,
|
||||||
Flow=flow,
|
Flow=flow,
|
||||||
Group = group,
|
Groupp =groupp,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@
|
|||||||
button1 = new Button();
|
button1 = new Button();
|
||||||
button2 = new Button();
|
button2 = new Button();
|
||||||
dataGridView1 = new DataGridView();
|
dataGridView1 = new DataGridView();
|
||||||
|
ColStudent = new DataGridViewComboBoxColumn();
|
||||||
|
ColValue = new DataGridViewTextBoxColumn();
|
||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
comboBoxSubject = new ComboBox();
|
comboBoxSubject = new ComboBox();
|
||||||
ColStudent = new DataGridViewComboBoxColumn();
|
|
||||||
ColSubject = new DataGridViewTextBoxColumn();
|
|
||||||
groupBox.SuspendLayout();
|
groupBox.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -151,7 +151,7 @@
|
|||||||
dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView1.Columns.AddRange(new DataGridViewColumn[] { ColStudent, ColSubject });
|
dataGridView1.Columns.AddRange(new DataGridViewColumn[] { ColStudent, ColValue });
|
||||||
dataGridView1.Location = new Point(26, 41);
|
dataGridView1.Location = new Point(26, 41);
|
||||||
dataGridView1.Margin = new Padding(3, 4, 3, 4);
|
dataGridView1.Margin = new Padding(3, 4, 3, 4);
|
||||||
dataGridView1.MultiSelect = false;
|
dataGridView1.MultiSelect = false;
|
||||||
@ -161,6 +161,21 @@
|
|||||||
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView1.Size = new Size(600, 207);
|
dataGridView1.Size = new Size(600, 207);
|
||||||
dataGridView1.TabIndex = 0;
|
dataGridView1.TabIndex = 0;
|
||||||
|
dataGridView1.CellContentClick += dataGridView1_CellContentClick;
|
||||||
|
//
|
||||||
|
// ColStudent
|
||||||
|
//
|
||||||
|
ColStudent.HeaderText = "Студент";
|
||||||
|
ColStudent.MinimumWidth = 8;
|
||||||
|
ColStudent.Name = "ColStudent";
|
||||||
|
//
|
||||||
|
// ColValue
|
||||||
|
//
|
||||||
|
ColValue.HeaderText = "Оценка";
|
||||||
|
ColValue.MinimumWidth = 8;
|
||||||
|
ColValue.Name = "ColValue";
|
||||||
|
ColValue.Resizable = DataGridViewTriState.True;
|
||||||
|
ColValue.SortMode = DataGridViewColumnSortMode.NotSortable;
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
@ -181,20 +196,6 @@
|
|||||||
comboBoxSubject.Size = new Size(286, 28);
|
comboBoxSubject.Size = new Size(286, 28);
|
||||||
comboBoxSubject.TabIndex = 36;
|
comboBoxSubject.TabIndex = 36;
|
||||||
//
|
//
|
||||||
// ColStudent
|
|
||||||
//
|
|
||||||
ColStudent.HeaderText = "Студент";
|
|
||||||
ColStudent.MinimumWidth = 8;
|
|
||||||
ColStudent.Name = "ColStudent";
|
|
||||||
//
|
|
||||||
// ColSubject
|
|
||||||
//
|
|
||||||
ColSubject.HeaderText = "Оценка";
|
|
||||||
ColSubject.MinimumWidth = 8;
|
|
||||||
ColSubject.Name = "ColSubject";
|
|
||||||
ColSubject.Resizable = DataGridViewTriState.True;
|
|
||||||
ColSubject.SortMode = DataGridViewColumnSortMode.NotSortable;
|
|
||||||
//
|
|
||||||
// FormMark
|
// FormMark
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -233,6 +234,6 @@
|
|||||||
private Label label1;
|
private Label label1;
|
||||||
private ComboBox comboBoxSubject;
|
private ComboBox comboBoxSubject;
|
||||||
private DataGridViewComboBoxColumn ColStudent;
|
private DataGridViewComboBoxColumn ColStudent;
|
||||||
private DataGridViewTextBoxColumn ColSubject;
|
private DataGridViewTextBoxColumn ColValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -44,7 +44,7 @@ namespace Academic_Performance.Forms
|
|||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
_statementRepository.CreateStatement(Statement.CreateOperation(0, 0, 0, CreateListMark()));
|
_statementRepository.CreateStatement(Statement.CreateOperation(0, (int)comboBoxSubject.SelectedValue!, (int)comboBoxTeacher.SelectedValue!, CreateListMark()));
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -60,14 +60,14 @@ namespace Academic_Performance.Forms
|
|||||||
var list = new List<Mark>();
|
var list = new List<Mark>();
|
||||||
foreach (DataGridViewRow row in dataGridView1.Rows)
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||||||
{
|
{
|
||||||
if (row.Cells["ColValue"].Value == null ||
|
if (
|
||||||
row.Cells["ColStudent"].Value == null)
|
row.Cells["ColStudent"].Value == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Add(Mark.CreateElement(0,0,0, Convert.ToInt32(row.Cells["ColStudent"].Value),
|
list.Add(Mark.CreateElement(0, Convert.ToInt32(row.Cells["ColStudent"].Value), (int)comboBoxSubject.SelectedValue!,(int)comboBoxTeacher.SelectedValue!,
|
||||||
Convert.ToInt32(row.Cells["ColSubject"].Value)
|
row.Cells["ColValue"].Value.ToString()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,11 +79,11 @@ namespace Academic_Performance.Forms
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (dataGridView1.RowCount < 1 ||
|
if (dataGridView1.RowCount < 1 ||
|
||||||
comboBoxTeacher.SelectedIndex < 0 || comboBoxSubject.SelectedIndex < 0 )
|
comboBoxTeacher.SelectedIndex < 0 || comboBoxSubject.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
_statementRepository.CreateStatement(Statement.CreateOperation(0,0,
|
_statementRepository.CreateStatement(Statement.CreateOperation(0, (int)comboBoxSubject.SelectedValue!,
|
||||||
(int)comboBoxTeacher.SelectedValue!,
|
(int)comboBoxTeacher.SelectedValue!,
|
||||||
CreateListMark()));
|
CreateListMark()));
|
||||||
Close();
|
Close();
|
||||||
@ -96,5 +96,9 @@ namespace Academic_Performance.Forms
|
|||||||
}
|
}
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@
|
|||||||
<metadata name="ColStudent.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColStudent.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="ColSubject.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="ColValue.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -18,14 +18,14 @@ namespace Academic_Performance.Forms
|
|||||||
{
|
{
|
||||||
private readonly IUnityContainer _container;
|
private readonly IUnityContainer _container;
|
||||||
|
|
||||||
private readonly IMarkRepository _markRepository;
|
private readonly IStatementRepository _statementRepository;
|
||||||
public FormMarks(IUnityContainer container, IMarkRepository markRepository)
|
public FormMarks(IUnityContainer container, IStatementRepository statementRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_container = container ??
|
_container = container ??
|
||||||
throw new ArgumentNullException(nameof(container));
|
throw new ArgumentNullException(nameof(container));
|
||||||
_markRepository = markRepository ??
|
_statementRepository = statementRepository ??
|
||||||
throw new ArgumentNullException(nameof(markRepository));
|
throw new ArgumentNullException(nameof(statementRepository));
|
||||||
}
|
}
|
||||||
private void buttonSave_Click(object sender, EventArgs e)
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -51,7 +51,7 @@ namespace Academic_Performance.Forms
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_markRepository.DeleteMark(findId);
|
_statementRepository.DeleteStatement(findId);
|
||||||
LoadList();
|
LoadList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -73,7 +73,7 @@ namespace Academic_Performance.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() =>
|
private void LoadList() =>
|
||||||
dataGridView.DataSource = _markRepository.ReadMark();
|
dataGridView.DataSource = _statementRepository.ReadStatement();
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
textBoxName = new TextBox();
|
textBoxName = new TextBox();
|
||||||
button1 = new Button();
|
button1 = new Button();
|
||||||
button2 = new Button();
|
button2 = new Button();
|
||||||
comboBoxFlow = new ComboBox();
|
|
||||||
checkedListBoxGroup = new CheckedListBox();
|
checkedListBoxGroup = new CheckedListBox();
|
||||||
|
textBoxFlow = new TextBox();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// label
|
// label
|
||||||
@ -97,16 +97,6 @@
|
|||||||
button2.Text = "Отмена";
|
button2.Text = "Отмена";
|
||||||
button2.UseVisualStyleBackColor = true;
|
button2.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// comboBoxFlow
|
|
||||||
//
|
|
||||||
comboBoxFlow.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
||||||
comboBoxFlow.FormattingEnabled = true;
|
|
||||||
comboBoxFlow.Location = new Point(137, 183);
|
|
||||||
comboBoxFlow.Margin = new Padding(2, 3, 2, 3);
|
|
||||||
comboBoxFlow.Name = "comboBoxFlow";
|
|
||||||
comboBoxFlow.Size = new Size(309, 28);
|
|
||||||
comboBoxFlow.TabIndex = 9;
|
|
||||||
//
|
|
||||||
// checkedListBoxGroup
|
// checkedListBoxGroup
|
||||||
//
|
//
|
||||||
checkedListBoxGroup.FormattingEnabled = true;
|
checkedListBoxGroup.FormattingEnabled = true;
|
||||||
@ -115,13 +105,21 @@
|
|||||||
checkedListBoxGroup.Size = new Size(309, 92);
|
checkedListBoxGroup.Size = new Size(309, 92);
|
||||||
checkedListBoxGroup.TabIndex = 10;
|
checkedListBoxGroup.TabIndex = 10;
|
||||||
//
|
//
|
||||||
|
// textBoxFlow
|
||||||
|
//
|
||||||
|
textBoxFlow.Location = new Point(137, 180);
|
||||||
|
textBoxFlow.Margin = new Padding(2, 3, 2, 3);
|
||||||
|
textBoxFlow.Name = "textBoxFlow";
|
||||||
|
textBoxFlow.Size = new Size(309, 27);
|
||||||
|
textBoxFlow.TabIndex = 11;
|
||||||
|
//
|
||||||
// FormStudent
|
// FormStudent
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(481, 311);
|
ClientSize = new Size(481, 311);
|
||||||
|
Controls.Add(textBoxFlow);
|
||||||
Controls.Add(checkedListBoxGroup);
|
Controls.Add(checkedListBoxGroup);
|
||||||
Controls.Add(comboBoxFlow);
|
|
||||||
Controls.Add(button2);
|
Controls.Add(button2);
|
||||||
Controls.Add(button1);
|
Controls.Add(button1);
|
||||||
Controls.Add(textBoxName);
|
Controls.Add(textBoxName);
|
||||||
@ -144,7 +142,7 @@
|
|||||||
private TextBox textBoxName;
|
private TextBox textBoxName;
|
||||||
private Button button1;
|
private Button button1;
|
||||||
private Button button2;
|
private Button button2;
|
||||||
private ComboBox comboBoxFlow;
|
|
||||||
private CheckedListBox checkedListBoxGroup;
|
private CheckedListBox checkedListBoxGroup;
|
||||||
|
private TextBox textBoxFlow;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,16 +30,16 @@ namespace Academic_Performance.Forms
|
|||||||
throw new InvalidDataException(nameof(student));
|
throw new InvalidDataException(nameof(student));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Group elem in Enum.GetValues(typeof(Group)))
|
foreach (Groupp elem in Enum.GetValues(typeof(Groupp)))
|
||||||
{
|
{
|
||||||
if ((elem & student.Group) != 0)
|
if ((elem & student.Groupp) != 0)
|
||||||
{
|
{
|
||||||
checkedListBoxGroup.SetItemChecked(checkedListBoxGroup.Items.IndexOf(elem), true);
|
checkedListBoxGroup.SetItemChecked(checkedListBoxGroup.Items.IndexOf(elem), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
textBoxName.Text = student.Name;
|
textBoxName.Text = student.Name;
|
||||||
comboBoxFlow.Text = student.Flow;
|
textBoxFlow.Text = student.Flow;
|
||||||
checkedListBoxGroup.SelectedItem =student.Group;
|
checkedListBoxGroup.SelectedItem =student.Groupp;
|
||||||
_studentId = value;
|
_studentId = value;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -56,7 +56,7 @@ namespace Academic_Performance.Forms
|
|||||||
_studentRepository = studentRepository ??
|
_studentRepository = studentRepository ??
|
||||||
throw new ArgumentNullException(nameof(studentRepository));
|
throw new ArgumentNullException(nameof(studentRepository));
|
||||||
|
|
||||||
foreach (var elem in Enum.GetValues(typeof(Group)))
|
foreach (var elem in Enum.GetValues(typeof(Groupp)))
|
||||||
{
|
{
|
||||||
checkedListBoxGroup.Items.Add(elem);
|
checkedListBoxGroup.Items.Add(elem);
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ namespace Academic_Performance.Forms
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(textBoxName.Text)|| string.IsNullOrWhiteSpace(comboBoxFlow.Text))
|
if (string.IsNullOrWhiteSpace(textBoxName.Text)|| string.IsNullOrWhiteSpace(textBoxFlow.Text))
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ namespace Academic_Performance.Forms
|
|||||||
}
|
}
|
||||||
private Student CreateStudent(int id) => Student.CreateEntity(
|
private Student CreateStudent(int id) => Student.CreateEntity(
|
||||||
id,
|
id,
|
||||||
textBoxName.Text, comboBoxFlow.Text, (Group)checkedListBoxGroup.SelectedItem!
|
textBoxName.Text, textBoxFlow.Text, (Groupp)checkedListBoxGroup.SelectedItem!
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@ using Unity.Lifetime;
|
|||||||
using Unity;
|
using Unity;
|
||||||
using Academic_Performance.Repositories;
|
using Academic_Performance.Repositories;
|
||||||
using Academic_Performance.Repositories.Implementations;
|
using Academic_Performance.Repositories.Implementations;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Serilog;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
|
||||||
namespace Academic_Performance
|
namespace Academic_Performance
|
||||||
{
|
{
|
||||||
@ -21,7 +25,10 @@ namespace Academic_Performance
|
|||||||
private static IUnityContainer CreateContainer()
|
private static IUnityContainer CreateContainer()
|
||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
container.RegisterType<IMarkRepository,MarkRepository>(new TransientLifetimeManager());
|
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
container.RegisterType<ISubjectRepository,SubjectRepository>(new TransientLifetimeManager());
|
container.RegisterType<ISubjectRepository,SubjectRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<ITeacherRepository, TeacherRepository>(new
|
container.RegisterType<ITeacherRepository, TeacherRepository>(new
|
||||||
TransientLifetimeManager());
|
TransientLifetimeManager());
|
||||||
@ -29,16 +36,28 @@ namespace Academic_Performance
|
|||||||
StudentRepository>(new TransientLifetimeManager());
|
StudentRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<IOrderRepository,
|
container.RegisterType<IOrderRepository,
|
||||||
OrderRepository>(new TransientLifetimeManager());
|
OrderRepository>(new TransientLifetimeManager());
|
||||||
container.RegisterType<IStatementRepository,
|
container.RegisterType<IStatementRepository,
|
||||||
StatementRepository>(new TransientLifetimeManager());
|
StatementRepository>(new TransientLifetimeManager());
|
||||||
return container;
|
container.RegisterType<IConnectionString,
|
||||||
|
ConnectionString>(new TransientLifetimeManager());
|
||||||
|
return container;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LoggerFactory CreateLoggerFactory()
|
||||||
|
{
|
||||||
|
var loggerFactory = new LoggerFactory();
|
||||||
|
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json")
|
||||||
|
.Build())
|
||||||
|
.CreateLogger());
|
||||||
|
return loggerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Npgsql;
|
||||||
|
|
||||||
|
namespace Academic_Performance.Repositories;
|
||||||
|
|
||||||
|
public interface IConnectionString
|
||||||
|
{
|
||||||
|
public string ConnectionString { get; }
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
using Academic_Performance.Entities;
|
|
||||||
using Academic_Performance.Entities.Enums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Academic_Performance.Repositories
|
|
||||||
{
|
|
||||||
public interface IMarkRepository
|
|
||||||
{ IEnumerable<Mark> ReadMark();
|
|
||||||
void CreateMark(Mark mark);
|
|
||||||
void DeleteMark(int id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,6 @@ namespace Academic_Performance.Repositories
|
|||||||
{
|
{
|
||||||
IEnumerable<Statement> ReadStatement();
|
IEnumerable<Statement> ReadStatement();
|
||||||
void CreateStatement(Statement statement);
|
void CreateStatement(Statement statement);
|
||||||
void UpdateStatement(Statement statement);
|
|
||||||
void DeleteStatement(int id);
|
void DeleteStatement(int id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.VisualBasic.ApplicationServices;
|
||||||
|
|
||||||
|
namespace Academic_Performance.Repositories.Implementations;
|
||||||
|
|
||||||
|
public class ConnectionString : IConnectionString
|
||||||
|
{
|
||||||
|
string IConnectionString.ConnectionString => "Server=127.0.0.1,5432;Database=postgres;Uid=A;Pwd=A;";
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
using Academic_Performance.Entities;
|
|
||||||
using Academic_Performance.Entities.Enums;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Academic_Performance.Repositories.Implementations
|
|
||||||
{
|
|
||||||
public class MarkRepository : IMarkRepository
|
|
||||||
{
|
|
||||||
public void CreateMark(Mark Mark)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void IMarkRepository.DeleteMark(int id)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<Mark> IMarkRepository.ReadMark()
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,9 @@
|
|||||||
using Academic_Performance.Entities;
|
using Academic_Performance.Entities;
|
||||||
using Academic_Performance.Entities.Enums;
|
using Academic_Performance.Entities.Enums;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -10,11 +14,46 @@ namespace Academic_Performance.Repositories.Implementations
|
|||||||
{
|
{
|
||||||
public class OrderRepository : IOrderRepository
|
public class OrderRepository : IOrderRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<OrderRepository> _logger;
|
||||||
|
public OrderRepository(IConnectionString connectionString, ILogger<OrderRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void AddOrder(Order order)
|
public void AddOrder(Order order)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(order));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"INSERT INTO Orderr(TypeS,Date,StudentId,Information)
|
||||||
|
VALUES (@TypeS,@Date,@StudentId,@Information)";
|
||||||
|
connection.Execute(queryInsert, order);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void DeleteOrder(int id)
|
public void DeleteOrder(int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Orderr WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<Order> GetAllOrders()
|
public IEnumerable<Order> GetAllOrders()
|
||||||
{
|
{
|
||||||
@ -22,14 +61,66 @@ namespace Academic_Performance.Repositories.Implementations
|
|||||||
}
|
}
|
||||||
public Order GetOrderById(int id)
|
public Order GetOrderById(int id)
|
||||||
{
|
{
|
||||||
return Order.CreateEntity(0,0, string.Empty,TypeS.None);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Orderr WHERE Id=@id";
|
||||||
|
var order = connection.QueryFirst<Order>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(order));
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void UpdateOrder(Order order)
|
public void UpdateOrder(Order order)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(order));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"UPDATE Orderr SET
|
||||||
|
Information=@Information,
|
||||||
|
TypeS=@TypeS,
|
||||||
|
Date=@Date,
|
||||||
|
StudentId=@StudentId
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryUpdate, order);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IEnumerable<Order> IOrderRepository.ReadOrder()
|
IEnumerable<Order> IOrderRepository.ReadOrder()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Orderr";
|
||||||
|
var order = connection.Query<Order>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(order));
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
using Academic_Performance.Entities;
|
using Academic_Performance.Entities;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Contracts;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,23 +14,101 @@ namespace Academic_Performance.Repositories.Implementations
|
|||||||
{
|
{
|
||||||
public class StatementRepository : IStatementRepository
|
public class StatementRepository : IStatementRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<StudentRepository> _logger;
|
||||||
|
public StatementRepository(IConnectionString connectionString, ILogger<StudentRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateStatement(Statement statement)
|
public void CreateStatement(Statement statement)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(statement));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
var queryInsert = @"INSERT INTO Statemant (TeacherId,SubjectId)
|
||||||
|
VALUES (@TeacherId, @SubjectId);
|
||||||
|
SELECT MAX(Id) FROM Statemant";
|
||||||
|
var statementId = connection.QueryFirst<int>(queryInsert, statement, transaction);
|
||||||
|
var querySubInsert = @"INSERT INTO Markkk(Value,StudentId)
|
||||||
|
VALUES (@Value,@StudentId)";
|
||||||
|
foreach (var elem in statement.Mark)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
|
||||||
|
elem.Value,
|
||||||
|
elem.StudentId
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void DeleteStatement(int id)
|
public void DeleteStatement(int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Statemant
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public IEnumerable<Statement> ReadStatements()
|
public IEnumerable<Statement> ReadStatements()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Statemant";
|
||||||
|
var statements = connection.Query<Statement>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(statements));
|
||||||
|
return statements;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateStatement(Statement statment)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public IEnumerable<Statement> ReadStatement()
|
public IEnumerable<Statement> ReadStatement()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Statemant";
|
||||||
|
var statements = connection.Query<Statement>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(statements));
|
||||||
|
return statements;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,35 +1,123 @@
|
|||||||
using Academic_Performance.Entities;
|
using Academic_Performance.Entities;
|
||||||
using Academic_Performance.Entities.Enums;
|
using Academic_Performance.Entities.Enums;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Academic_Performance.Repositories.Implementations
|
namespace Academic_Performance.Repositories.Implementations
|
||||||
{
|
{
|
||||||
public class StudentRepository : IStudentRepository
|
public class StudentRepository : IStudentRepository
|
||||||
{
|
{
|
||||||
public void AddStudent(Student subject)
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<StudentRepository> _logger;
|
||||||
|
public StudentRepository(IConnectionString connectionString, ILogger<StudentRepository> logger)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
public void AddStudent(Student student)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(student));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"INSERT INTO Studentt (Name, Groupp, Flow)
|
||||||
|
VALUES (@Name, @Groupp, @Flow)";
|
||||||
|
connection.Execute(queryInsert, student);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void DeleteStudent(int id)
|
public void DeleteStudent(int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Studentt WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<Student> GetAllStudents()
|
|
||||||
{
|
|
||||||
return new List<Student>();
|
|
||||||
}
|
|
||||||
public Student GetStudentById(int id)
|
public Student GetStudentById(int id)
|
||||||
{
|
{
|
||||||
return Student.CreateEntity(0, string.Empty,string.Empty ,Group.None);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Studentt WHERE Id=@id";
|
||||||
|
var student = connection.QueryFirst<Student>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(student));
|
||||||
|
return student;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void UpdateStudent(Student student)
|
public void UpdateStudent(Student student)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(student));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"UPDATE Studentt SET
|
||||||
|
Name=@Name,
|
||||||
|
Groupp=@Groupp,
|
||||||
|
Flow=@Flow
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryUpdate, student);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IEnumerable<Student> IStudentRepository.ReadStudent()
|
IEnumerable<Student> IStudentRepository.ReadStudent()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Studentt";
|
||||||
|
var students = connection.Query<Student>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(students));
|
||||||
|
return students;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
using Academic_Performance.Entities;
|
using Academic_Performance.Entities;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.VisualBasic.Devices;
|
using Microsoft.VisualBasic.Devices;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -10,22 +14,107 @@ namespace Academic_Performance.Repositories.Implementations
|
|||||||
{
|
{
|
||||||
public class SubjectRepository : ISubjectRepository
|
public class SubjectRepository : ISubjectRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<SubjectRepository> _logger;
|
||||||
|
public SubjectRepository(IConnectionString connectionString, ILogger<SubjectRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void AddSubject(Subject subject)
|
public void AddSubject(Subject subject)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(subject));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"INSERT INTO Subject(Name)
|
||||||
|
VALUES (@Name)";
|
||||||
|
connection.Execute(queryInsert, subject);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void DeleteSubject(int id)
|
public void DeleteSubject(int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Subject WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public Subject GetSubjectById(int id)
|
public Subject GetSubjectById(int id)
|
||||||
{
|
{
|
||||||
return Subject.CreateEntity(0, string.Empty);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Subject WHERE Id=@id";
|
||||||
|
var subject = connection.QueryFirst<Subject>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(subject));
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void UpdateSubject(Subject subject)
|
public void UpdateSubject(Subject subject)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(subject));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"UPDATE Subject SET
|
||||||
|
Name=@Name
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryUpdate, subject);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IEnumerable<Subject> ISubjectRepository.ReadSubject()
|
public IEnumerable<Subject> ReadSubject()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Subject";
|
||||||
|
var subjects = connection.Query<Subject>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(subjects));
|
||||||
|
return subjects;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
using Academic_Performance.Entities;
|
using Academic_Performance.Entities;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -9,26 +13,108 @@ namespace Academic_Performance.Repositories.Implementations
|
|||||||
{
|
{
|
||||||
public class TeacherRepository : ITeacherRepository
|
public class TeacherRepository : ITeacherRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<TeacherRepository> _logger;
|
||||||
|
public TeacherRepository(IConnectionString connectionString, ILogger<TeacherRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateTeacher(Teacher teacher)
|
public void CreateTeacher(Teacher teacher)
|
||||||
{
|
{
|
||||||
}
|
_logger.LogInformation("Добавление объекта");
|
||||||
public void DeleteTeacher(int id)
|
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(teacher));
|
||||||
{
|
try
|
||||||
}
|
{
|
||||||
public IEnumerable<Teacher> GetAllTeachers()
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
{
|
var queryInsert = @"INSERT INTO Teacher(Name)
|
||||||
return new List<Teacher>();
|
VALUES (@Name)";
|
||||||
}
|
connection.Execute(queryInsert, teacher);
|
||||||
public Teacher GetTeacherById(int id)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
return Teacher.CreateEntity(0, string.Empty);
|
{
|
||||||
}
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
public IEnumerable<Teacher> ReadTeachers()
|
throw;
|
||||||
{
|
}
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
public void UpdateTeacher(Teacher teacher)
|
public void UpdateTeacher(Teacher teacher)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(teacher));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"UPDATE Teacher SET
|
||||||
|
Name=@Name
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryUpdate, teacher);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
public void DeleteTeacher(int id)
|
||||||
|
{
|
||||||
|
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"DELETE FROM Teacher WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Teacher GetTeacherById(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"SELECT * FROM Teacher WHERE Id=@id";
|
||||||
|
var teacher = connection.QueryFirst<Teacher>(querySelect, new
|
||||||
|
{
|
||||||
|
id
|
||||||
|
});
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(teacher));
|
||||||
|
return teacher;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<Teacher> ReadTeachers()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Teacher";
|
||||||
|
var teachers = connection.Query<Teacher>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(teachers));
|
||||||
|
return teachers;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
Academic_Performance/Academic_Performance/appsettings.json
Normal file
15
Academic_Performance/Academic_Performance/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/Academic_log.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user