ПИбд-22. Халиуллов Р.М. Лабораторная работа №2 #2
@ -9,14 +9,16 @@ namespace ProjectShedule.Entities;
|
|||||||
|
|
||||||
public class CurriculumSubject
|
public class CurriculumSubject
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
public int CurriculumId { get; private set; }
|
public int CurriculumId { get; private set; }
|
||||||
public IEnumerable<SubjectSubject> SubjectSubject { get; private set; } = [];
|
public IEnumerable<SubjectSubject> SubjectSubject { get; private set; } = [];
|
||||||
public Course Course { get; private set; }
|
public Course Course { get; private set; }
|
||||||
|
|
||||||
public static CurriculumSubject CreateCurriculumSubject(int curriculumId, Course course, IEnumerable<SubjectSubject> subjectSubjects)
|
public static CurriculumSubject CreateCurriculumSubject(int id, int curriculumId, Course course, IEnumerable<SubjectSubject> subjectSubjects)
|
||||||
{
|
{
|
||||||
return new CurriculumSubject()
|
return new CurriculumSubject()
|
||||||
{
|
{
|
||||||
|
Id = id,
|
||||||
CurriculumId = curriculumId,
|
CurriculumId = curriculumId,
|
||||||
Course = course,
|
Course = course,
|
||||||
SubjectSubject = subjectSubjects
|
SubjectSubject = subjectSubjects
|
||||||
|
@ -12,20 +12,21 @@ public class Shedule
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public DateTime Date { get; private set; }
|
public DateTime Date { get; private set; }
|
||||||
public PairNumber PairNumber { get; private set; }
|
public PairNumber PairNumber { get; private set; }
|
||||||
public int GroupId { get; private set; }
|
public int StudentsGroupId { get; private set; }
|
||||||
public int TeacherId { get; private set; }
|
public int TeacherId { get; private set; }
|
||||||
public int SubjectId { get; private set; }
|
public int SubjectId { get; private set; }
|
||||||
public int ClassroomId { get; private set; }
|
public int ClassroomId { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public static Shedule CreateOperation(int id, DateTime date, PairNumber pairNumber, int groupId, int teacherId, int subjectId, int classroomId)
|
public static Shedule CreateOperation(int id, DateTime date, PairNumber pairNumber
|
||||||
|
, int studentsGroupId, int teacherId, int subjectId, int classroomId)
|
||||||
{
|
{
|
||||||
return new Shedule
|
return new Shedule
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
Date = date,
|
Date = date,
|
||||||
PairNumber = pairNumber,
|
PairNumber = pairNumber,
|
||||||
GroupId = groupId,
|
StudentsGroupId = studentsGroupId,
|
||||||
TeacherId = teacherId,
|
TeacherId = teacherId,
|
||||||
SubjectId = subjectId,
|
SubjectId = subjectId,
|
||||||
ClassroomId = classroomId
|
ClassroomId = classroomId
|
||||||
|
@ -7,16 +7,16 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectShedule.Entities;
|
namespace ProjectShedule.Entities;
|
||||||
|
|
||||||
public class Group
|
public class StudentsGroup
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int StudentsCount { get; private set; }
|
public int StudentsCount { get; private set; }
|
||||||
public string GroupNumber { get; private set; } = String.Empty;
|
public string GroupNumber { get; private set; } = String.Empty;
|
||||||
public Course Course { get; private set; }
|
public Course Course { get; private set; }
|
||||||
public int CurriculumId { get; private set; }
|
public int CurriculumId { get; private set; }
|
||||||
public static Group CreateGroup(int id, int studentsCount, string groupNumber, Course course, int curriculumId)
|
public static StudentsGroup CreateGroup(int id, int studentsCount, string groupNumber, Course course, int curriculumId)
|
||||||
{
|
{
|
||||||
return new Group
|
return new StudentsGroup
|
||||||
{
|
{
|
||||||
Id = id,
|
Id = id,
|
||||||
StudentsCount = studentsCount,
|
StudentsCount = studentsCount,
|
@ -84,7 +84,7 @@
|
|||||||
//
|
//
|
||||||
curriculumsToolStripMenuItem.Name = "curriculumsToolStripMenuItem";
|
curriculumsToolStripMenuItem.Name = "curriculumsToolStripMenuItem";
|
||||||
curriculumsToolStripMenuItem.Size = new Size(224, 26);
|
curriculumsToolStripMenuItem.Size = new Size(224, 26);
|
||||||
curriculumsToolStripMenuItem.Text = "Учебные планы";
|
curriculumsToolStripMenuItem.Text = "Направлении";
|
||||||
curriculumsToolStripMenuItem.Click += curriculumsToolStripMenuItem_Click;
|
curriculumsToolStripMenuItem.Click += curriculumsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// studentGroupsToolStripMenuItem
|
// studentGroupsToolStripMenuItem
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
using ProjectShedule.Entities;
|
using ProjectShedule.Entities;
|
||||||
using ProjectShedule.Entities.Enums;
|
using ProjectShedule.Entities.Enums;
|
||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
{
|
{
|
||||||
@ -63,7 +54,7 @@ namespace ProjectShedule.Forms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_classroomRepository.UpdateClassroom(CreateClassroom(0));
|
_classroomRepository.CreateClassroom(CreateClassroom(0));
|
||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@
|
|||||||
Controls.Add(textBoxCurriculumName);
|
Controls.Add(textBoxCurriculumName);
|
||||||
Controls.Add(label2);
|
Controls.Add(label2);
|
||||||
Name = "FormCurriculum";
|
Name = "FormCurriculum";
|
||||||
Text = "Учебный план(дисциплина)";
|
Text = "Учебный план(направление)";
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ namespace ProjectShedule.Forms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_curriculumRepository.UpdateCurriculum(CreateCurriculum(0));
|
_curriculumRepository.CreateCurriculum(CreateCurriculum(0));
|
||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,14 @@ namespace ProjectShedule.Forms
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (comboBoxDirection.SelectedIndex < 0 ||
|
if (comboBoxDirection.SelectedIndex < 0 ||
|
||||||
comboBoxCourse.SelectedIndex < 0 || dataGridView.RowCount < 1)
|
comboBoxCourse.SelectedIndex < 1 || dataGridView.RowCount < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Есть незаполненные поля");
|
throw new Exception("Есть незаполненные поля");
|
||||||
}
|
}
|
||||||
_curriculumSubjectRepository.CreateCurriculumSubject(CurriculumSubject.CreateCurriculumSubject(
|
_curriculumSubjectRepository.CreateCurriculumSubject(CurriculumSubject.CreateCurriculumSubject(0,
|
||||||
(int)comboBoxDirection.SelectedValue!,
|
(int)comboBoxDirection.SelectedValue!,
|
||||||
(Course)comboBoxCourse.SelectedItem!, CreateListSubjectSubjectFromDataGrid()));
|
(Course)comboBoxCourse.SelectedItem!,
|
||||||
|
CreateListSubjectSubjectFromDataGrid()));
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
panel1 = new Panel();
|
panel1 = new Panel();
|
||||||
|
buttonDel = new Button();
|
||||||
buttonAdd = new Button();
|
buttonAdd = new Button();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
@ -37,18 +38,30 @@
|
|||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
|
panel1.Controls.Add(buttonDel);
|
||||||
panel1.Controls.Add(buttonAdd);
|
panel1.Controls.Add(buttonAdd);
|
||||||
panel1.Dock = DockStyle.Right;
|
panel1.Dock = DockStyle.Right;
|
||||||
panel1.Location = new Point(622, 0);
|
panel1.Location = new Point(600, 0);
|
||||||
panel1.Name = "panel1";
|
panel1.Name = "panel1";
|
||||||
panel1.Size = new Size(178, 352);
|
panel1.Size = new Size(200, 352);
|
||||||
panel1.TabIndex = 2;
|
panel1.TabIndex = 2;
|
||||||
//
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
buttonDel.BackgroundImage = Properties.Resources.minus_PNG39;
|
||||||
|
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
|
buttonDel.Location = new Point(42, 214);
|
||||||
|
buttonDel.Name = "buttonDel";
|
||||||
|
buttonDel.Size = new Size(94, 93);
|
||||||
|
buttonDel.TabIndex = 4;
|
||||||
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonDel.Click += buttonDel_Click;
|
||||||
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.BackgroundImage = Properties.Resources.Ambox_plus_svg;
|
buttonAdd.BackgroundImage = Properties.Resources.Ambox_plus_svg;
|
||||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonAdd.Location = new Point(42, 125);
|
buttonAdd.Location = new Point(42, 45);
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(94, 93);
|
buttonAdd.Size = new Size(94, 93);
|
||||||
buttonAdd.TabIndex = 0;
|
buttonAdd.TabIndex = 0;
|
||||||
@ -63,7 +76,6 @@
|
|||||||
dataGridView.AllowUserToResizeRows = false;
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Dock = DockStyle.Fill;
|
|
||||||
dataGridView.Location = new Point(0, 0);
|
dataGridView.Location = new Point(0, 0);
|
||||||
dataGridView.MultiSelect = false;
|
dataGridView.MultiSelect = false;
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
@ -71,7 +83,7 @@
|
|||||||
dataGridView.RowHeadersVisible = false;
|
dataGridView.RowHeadersVisible = false;
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView.Size = new Size(800, 352);
|
dataGridView.Size = new Size(601, 352);
|
||||||
dataGridView.TabIndex = 3;
|
dataGridView.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// FormCurriculumSubjects
|
// FormCurriculumSubjects
|
||||||
@ -82,7 +94,7 @@
|
|||||||
Controls.Add(panel1);
|
Controls.Add(panel1);
|
||||||
Controls.Add(dataGridView);
|
Controls.Add(dataGridView);
|
||||||
Name = "FormCurriculumSubjects";
|
Name = "FormCurriculumSubjects";
|
||||||
Text = "FormCurriculumSubjects";
|
Text = "Учебные планы";
|
||||||
Load += FormCurriculumSubjects_Load;
|
Load += FormCurriculumSubjects_Load;
|
||||||
panel1.ResumeLayout(false);
|
panel1.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
@ -94,5 +106,6 @@
|
|||||||
private Panel panel1;
|
private Panel panel1;
|
||||||
private Button buttonAdd;
|
private Button buttonAdd;
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
|
private Button buttonDel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -41,5 +41,41 @@ namespace ProjectShedule.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridView.DataSource = _curriculumSubjectRepository.ReadCurriculumSubject();
|
private void LoadList() => dataGridView.DataSource = _curriculumSubjectRepository.ReadCurriculumSubject();
|
||||||
|
|
||||||
|
private void buttonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_curriculumSubjectRepository.DeleteCurriculumSubject(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[id].Value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,6 @@
|
|||||||
dataGridView.AllowUserToResizeRows = false;
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Dock = DockStyle.Fill;
|
|
||||||
dataGridView.Location = new Point(0, 0);
|
dataGridView.Location = new Point(0, 0);
|
||||||
dataGridView.MultiSelect = false;
|
dataGridView.MultiSelect = false;
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
@ -97,7 +96,7 @@
|
|||||||
dataGridView.RowHeadersVisible = false;
|
dataGridView.RowHeadersVisible = false;
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView.Size = new Size(800, 353);
|
dataGridView.Size = new Size(625, 353);
|
||||||
dataGridView.TabIndex = 3;
|
dataGridView.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// FormCurriculums
|
// FormCurriculums
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
|
@ -1,17 +1,6 @@
|
|||||||
using ProjectShedule.Entities;
|
using ProjectShedule.Entities;
|
||||||
using ProjectShedule.Entities.Enums;
|
using ProjectShedule.Entities.Enums;
|
||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
{
|
{
|
||||||
public partial class FormGroup : Form
|
public partial class FormGroup : Form
|
||||||
@ -59,7 +48,7 @@ namespace ProjectShedule.Forms
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(textBoxGroupName.Text) || comboBoxCourse.SelectedIndex < 1 ||
|
if (string.IsNullOrWhiteSpace(textBoxGroupName.Text) || comboBoxCourse.SelectedIndex < 1 ||
|
||||||
comboBoxCurriculum.SelectedIndex < 1)
|
comboBoxCurriculum.SelectedIndex < 0)
|
||||||
{
|
{
|
||||||
throw new Exception("Имеются незаполненные поля");
|
throw new Exception("Имеются незаполненные поля");
|
||||||
}
|
}
|
||||||
@ -80,11 +69,11 @@ namespace ProjectShedule.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
private void buttonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
private Group CreateGroup(int id) => Group.CreateGroup(
|
private StudentsGroup CreateGroup(int id) => StudentsGroup.CreateGroup(
|
||||||
id,
|
id,
|
||||||
Convert.ToInt32(numericUpDownStudentsCount.Value),
|
Convert.ToInt32(numericUpDownStudentsCount.Value),
|
||||||
textBoxGroupName.Text,
|
textBoxGroupName.Text,
|
||||||
(Course)comboBoxCourse.SelectedItem!,
|
(Course)comboBoxCourse.SelectedItem!,
|
||||||
(int)comboBoxCourse.SelectedValue!);
|
(int)comboBoxCurriculum.SelectedValue!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,6 @@
|
|||||||
dataGridView.AllowUserToResizeRows = false;
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Dock = DockStyle.Fill;
|
|
||||||
dataGridView.Location = new Point(0, 0);
|
dataGridView.Location = new Point(0, 0);
|
||||||
dataGridView.MultiSelect = false;
|
dataGridView.MultiSelect = false;
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
@ -97,7 +96,7 @@
|
|||||||
dataGridView.RowHeadersVisible = false;
|
dataGridView.RowHeadersVisible = false;
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView.Size = new Size(800, 354);
|
dataGridView.Size = new Size(626, 354);
|
||||||
dataGridView.TabIndex = 5;
|
dataGridView.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// FormGroups
|
// FormGroups
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
using ProjectShedule.Entities;
|
using ProjectShedule.Entities;
|
||||||
using ProjectShedule.Entities.Enums;
|
using ProjectShedule.Entities.Enums;
|
||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using System.Diagnostics.Contracts;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
buttonAdd = new Button();
|
buttonAdd = new Button();
|
||||||
panel1 = new Panel();
|
panel1 = new Panel();
|
||||||
|
buttonDel = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -58,7 +59,7 @@
|
|||||||
//
|
//
|
||||||
buttonAdd.BackgroundImage = Properties.Resources.Ambox_plus_svg;
|
buttonAdd.BackgroundImage = Properties.Resources.Ambox_plus_svg;
|
||||||
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
buttonAdd.Location = new Point(48, 112);
|
buttonAdd.Location = new Point(42, 46);
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(94, 93);
|
buttonAdd.Size = new Size(94, 93);
|
||||||
buttonAdd.TabIndex = 0;
|
buttonAdd.TabIndex = 0;
|
||||||
@ -67,6 +68,7 @@
|
|||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
|
panel1.Controls.Add(buttonDel);
|
||||||
panel1.Controls.Add(buttonAdd);
|
panel1.Controls.Add(buttonAdd);
|
||||||
panel1.Dock = DockStyle.Right;
|
panel1.Dock = DockStyle.Right;
|
||||||
panel1.Location = new Point(622, 0);
|
panel1.Location = new Point(622, 0);
|
||||||
@ -74,6 +76,17 @@
|
|||||||
panel1.Size = new Size(178, 315);
|
panel1.Size = new Size(178, 315);
|
||||||
panel1.TabIndex = 4;
|
panel1.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
buttonDel.BackgroundImage = Properties.Resources.minus_PNG39;
|
||||||
|
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
|
||||||
|
buttonDel.Location = new Point(42, 175);
|
||||||
|
buttonDel.Name = "buttonDel";
|
||||||
|
buttonDel.Size = new Size(94, 93);
|
||||||
|
buttonDel.TabIndex = 4;
|
||||||
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonDel.Click += buttonDel_Click;
|
||||||
|
//
|
||||||
// FormShedules
|
// FormShedules
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -94,5 +107,6 @@
|
|||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView;
|
||||||
private Button buttonAdd;
|
private Button buttonAdd;
|
||||||
private Panel panel1;
|
private Panel panel1;
|
||||||
|
private Button buttonDel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,4 @@
|
|||||||
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories;
|
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
@ -45,5 +43,42 @@ namespace ProjectShedule.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void LoadList() => dataGridView.DataSource = _sheduleRepository.ReadShedule();
|
private void LoadList() => dataGridView.DataSource = _sheduleRepository.ReadShedule();
|
||||||
|
|
||||||
|
private void buttonDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (TryGetIdentifierFromSelectedRow(out var findId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_sheduleRepository.DeleteShedule(findId);
|
||||||
|
LoadList();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
{
|
||||||
|
id = 0;
|
||||||
|
if (dataGridView.SelectedRows.Count < 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[id].Value);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
using ProjectShedule.Entities.Enums;
|
using ProjectShedule.Entities;
|
||||||
using ProjectShedule.Entities;
|
|
||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Forms;
|
namespace ProjectShedule.Forms;
|
||||||
|
|
||||||
@ -60,7 +50,7 @@ public partial class FormSubject : Form
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_subjectRepository.UpdateSubject(CreateSubject(0));
|
_subjectRepository.CreateSubject(CreateSubject(0));
|
||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,6 @@
|
|||||||
dataGridView.AllowUserToResizeRows = false;
|
dataGridView.AllowUserToResizeRows = false;
|
||||||
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Dock = DockStyle.Fill;
|
|
||||||
dataGridView.Location = new Point(0, 0);
|
dataGridView.Location = new Point(0, 0);
|
||||||
dataGridView.MultiSelect = false;
|
dataGridView.MultiSelect = false;
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.Name = "dataGridView";
|
||||||
@ -97,7 +96,7 @@
|
|||||||
dataGridView.RowHeadersVisible = false;
|
dataGridView.RowHeadersVisible = false;
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dataGridView.Size = new Size(800, 354);
|
dataGridView.Size = new Size(623, 354);
|
||||||
dataGridView.TabIndex = 3;
|
dataGridView.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// FormSubjects
|
// FormSubjects
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
|
@ -1,15 +1,5 @@
|
|||||||
using ProjectShedule.Entities;
|
using ProjectShedule.Entities;
|
||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
{
|
{
|
||||||
@ -61,7 +51,7 @@ namespace ProjectShedule.Forms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_teacherRepository.UpdateTeacher(CreateTeacher(0));
|
_teacherRepository.CreateTeacher(CreateTeacher(0));
|
||||||
}
|
}
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using Unity;
|
using Unity;
|
||||||
|
|
||||||
namespace ProjectShedule.Forms
|
namespace ProjectShedule.Forms
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using ProjectShedule.Repositories;
|
using ProjectShedule.Repositories;
|
||||||
using ProjectShedule.Repositories.Implementations;
|
using ProjectShedule.Repositories.Implementations;
|
||||||
|
using Serilog;
|
||||||
using Unity;
|
using Unity;
|
||||||
|
using Unity.Microsoft.Logging;
|
||||||
|
|
||||||
namespace ProjectShedule
|
namespace ProjectShedule
|
||||||
{
|
{
|
||||||
@ -21,6 +25,9 @@ namespace ProjectShedule
|
|||||||
{
|
{
|
||||||
var container = new UnityContainer();
|
var container = new UnityContainer();
|
||||||
|
|
||||||
|
container.AddExtension(new
|
||||||
|
LoggingExtension(CreateLoggerFactory()));
|
||||||
|
|
||||||
container.RegisterType<IClassroomRepository, ClassroomRepository>();
|
container.RegisterType<IClassroomRepository, ClassroomRepository>();
|
||||||
container.RegisterType<ICurriculumRepository, CurriculumRepository>();
|
container.RegisterType<ICurriculumRepository, CurriculumRepository>();
|
||||||
container.RegisterType<IGroupRepository, GroupRepository>();
|
container.RegisterType<IGroupRepository, GroupRepository>();
|
||||||
@ -28,8 +35,21 @@ namespace ProjectShedule
|
|||||||
container.RegisterType<ISubjectRepository, SubjectRepository>();
|
container.RegisterType<ISubjectRepository, SubjectRepository>();
|
||||||
container.RegisterType<ITeacherRepository, TeacherRepository>();
|
container.RegisterType<ITeacherRepository, TeacherRepository>();
|
||||||
container.RegisterType<ICurriculumSubjectRepository, CurriculumSubjectRepository>();
|
container.RegisterType<ICurriculumSubjectRepository, CurriculumSubjectRepository>();
|
||||||
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
return container;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,19 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Npgsql" Version="8.0.5" />
|
||||||
|
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
|
||||||
<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 +39,12 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="https://json.schemastore.org/appsscript.json" /></VisualStudio></ProjectExtensions>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectShedule.Repositories;
|
||||||
|
|
||||||
|
public interface IConnectionString
|
||||||
|
{
|
||||||
|
public string ConnectionString { get;}
|
||||||
|
}
|
@ -5,5 +5,6 @@ namespace ProjectShedule.Repositories;
|
|||||||
public interface ICurriculumSubjectRepository
|
public interface ICurriculumSubjectRepository
|
||||||
{
|
{
|
||||||
IEnumerable<CurriculumSubject> ReadCurriculumSubject();
|
IEnumerable<CurriculumSubject> ReadCurriculumSubject();
|
||||||
|
void DeleteCurriculumSubject(int id);
|
||||||
void CreateCurriculumSubject(CurriculumSubject curriculumSubject);
|
void CreateCurriculumSubject(CurriculumSubject curriculumSubject);
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ namespace ProjectShedule.Repositories;
|
|||||||
|
|
||||||
public interface IGroupRepository
|
public interface IGroupRepository
|
||||||
{
|
{
|
||||||
IEnumerable<Group> ReadGroup();
|
IEnumerable<StudentsGroup> ReadGroup();
|
||||||
Group ReadGroupById(int id);
|
StudentsGroup ReadGroupById(int id);
|
||||||
void CreateGroup(Group group);
|
void CreateGroup(StudentsGroup group);
|
||||||
void UpdateGroup(Group group);
|
void UpdateGroup(StudentsGroup group);
|
||||||
void DeleteGroup(int id);
|
void DeleteGroup(int id);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,5 @@ public interface ISheduleRepository
|
|||||||
{
|
{
|
||||||
IEnumerable<Shedule> ReadShedule(DateTime? dateTime = null, int? groupId = null);
|
IEnumerable<Shedule> ReadShedule(DateTime? dateTime = null, int? groupId = null);
|
||||||
void CreateShedule(Shedule shedule);
|
void CreateShedule(Shedule shedule);
|
||||||
void UpdateShedule(Shedule shedule);
|
|
||||||
void DeleteShedule(int id);
|
void DeleteShedule(int id);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,124 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Npgsql;
|
||||||
|
using ProjectShedule.Entities;
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.Repositories.Implementations;
|
||||||
|
|
||||||
public class ClassroomRepository : IClassroomRepository
|
public class ClassroomRepository : IClassroomRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
|
||||||
|
private readonly ILogger<ClassroomRepository> _logger;
|
||||||
|
|
||||||
|
public ClassroomRepository(IConnectionString connectionString, ILogger<ClassroomRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateClassroom(Classroom classroom)
|
public void CreateClassroom(Classroom classroom)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(classroom));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Classroom (Size, Name, ClassType)
|
||||||
|
VALUES (@Size, @Name, @ClassType)";
|
||||||
|
connection.Execute(queryInsert, classroom);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteClassroom(int id)
|
public void DeleteClassroom(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Classroom
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Classroom> ReadClassroom()
|
public IEnumerable<Classroom> ReadClassroom()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Classroom";
|
||||||
|
var classroms = connection.Query<Classroom>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(classroms));
|
||||||
|
return classroms;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Classroom ReadClassroomById(int id)
|
public Classroom ReadClassroomById(int id)
|
||||||
{
|
{
|
||||||
return Classroom.CreateClassroom(0, 0, string.Empty, 0);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Classroom
|
||||||
|
WHERE Id= @id";
|
||||||
|
var classroom = connection.QueryFirst<Classroom>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(classroom));
|
||||||
|
return classroom;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateClassroom(Classroom classroom)
|
public void UpdateClassroom(Classroom classroom)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(classroom));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Classroom
|
||||||
|
SET
|
||||||
|
Size= @Size,
|
||||||
|
Name= @Name,
|
||||||
|
ClassType = @ClassType
|
||||||
|
WHERE Id= @Id";
|
||||||
|
connection.Execute(queryUpdate, classroom);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace ProjectShedule.Repositories.Implementations;
|
||||||
|
|
||||||
|
public class ConnectionString : IConnectionString
|
||||||
|
{
|
||||||
|
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Username=postgres;Password=Xaliullov05;Database=otp;Include Error Detail=true";
|
||||||
|
}
|
@ -1,33 +1,119 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using Npgsql;
|
||||||
using System.Text;
|
using ProjectShedule.Entities;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.Repositories.Implementations;
|
||||||
|
|
||||||
public class CurriculumRepository : ICurriculumRepository
|
public class CurriculumRepository : ICurriculumRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<CurriculumRepository> _logger;
|
||||||
|
public CurriculumRepository(IConnectionString connectionString, ILogger<CurriculumRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateCurriculum(Curriculum curriculum)
|
public void CreateCurriculum(Curriculum curriculum)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(curriculum));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Curriculum (Direction)
|
||||||
|
VALUES (@Direction)";
|
||||||
|
connection.Execute(queryInsert, curriculum);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteCurriculum(int id)
|
public void DeleteCurriculum(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Curriculum
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Curriculum> ReadCurriculum()
|
public IEnumerable<Curriculum> ReadCurriculum()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM Curriculum";
|
||||||
|
var curriculums = connection.Query<Curriculum>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(curriculums));
|
||||||
|
return curriculums;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Curriculum ReadCurriculumById(int id)
|
public Curriculum ReadCurriculumById(int id)
|
||||||
{
|
{
|
||||||
return Curriculum.CreateCurriculum(0, string.Empty);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM Curriculum
|
||||||
|
WHERE Id= @id";
|
||||||
|
var curriculum = connection.QueryFirst<Curriculum>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(curriculum));
|
||||||
|
return curriculum;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCurriculum(Curriculum curriculum)
|
public void UpdateCurriculum(Curriculum curriculum)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(curriculum));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE Curriculum
|
||||||
|
SET
|
||||||
|
Direction= @Direction
|
||||||
|
WHERE Id= @Id";
|
||||||
|
connection.Execute(queryUpdate, curriculum);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,93 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
using ProjectShedule.Entities.Enums;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
using Npgsql;
|
||||||
using System.Linq;
|
using ProjectShedule.Entities;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.Repositories.Implementations;
|
||||||
|
|
||||||
public class CurriculumSubjectRepository : ICurriculumSubjectRepository
|
public class CurriculumSubjectRepository : ICurriculumSubjectRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<CurriculumSubjectRepository> _logger;
|
||||||
|
public CurriculumSubjectRepository(IConnectionString connectionString, ILogger<CurriculumSubjectRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateCurriculumSubject(CurriculumSubject curriculumSubject)
|
public void CreateCurriculumSubject(CurriculumSubject curriculumSubject)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(curriculumSubject));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new
|
||||||
|
NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
var queryInsert =
|
||||||
|
@"
|
||||||
|
INSERT INTO CurriculumSubject (CurriculumId, Course)
|
||||||
|
VALUES (@CurriculumId, @Course);
|
||||||
|
SELECT MAX(Id) FROM CurriculumSubject";
|
||||||
|
var curriculumSubjectId =
|
||||||
|
connection.QueryFirst<int>(queryInsert, curriculumSubject, transaction);
|
||||||
|
var querySubInsert = @"
|
||||||
|
INSERT INTO SubjectSubject (CurriculumSubjectId, SubjectId, LessonsCount)
|
||||||
|
VALUES (@CurriculumSubjectId, @SubjectId, @LessonsCount)";
|
||||||
|
|
||||||
|
foreach (var elem in curriculumSubject.SubjectSubject)
|
||||||
|
{
|
||||||
|
connection.Execute(querySubInsert, new
|
||||||
|
{
|
||||||
|
curriculumSubjectId,
|
||||||
|
elem.SubjectId,
|
||||||
|
elem.LessonsCount
|
||||||
|
}, transaction);
|
||||||
|
}
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DeleteCurriculumSubject(int id)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM CurriculumSubject
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<CurriculumSubject> ReadCurriculumSubject()
|
public IEnumerable<CurriculumSubject> ReadCurriculumSubject()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM CurriculumSubject";
|
||||||
|
var curriculumSubjects = connection.Query<CurriculumSubject>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(curriculumSubjects));
|
||||||
|
return curriculumSubjects;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,123 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using Npgsql;
|
||||||
using System.Text;
|
using ProjectShedule.Entities;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.Repositories.Implementations;
|
||||||
|
|
||||||
public class GroupRepository : IGroupRepository
|
public class GroupRepository : IGroupRepository
|
||||||
{
|
{
|
||||||
public void CreateGroup(Group group)
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<GroupRepository> _logger;
|
||||||
|
public GroupRepository(IConnectionString connectionString, ILogger<GroupRepository> logger)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
public void CreateGroup(StudentsGroup group)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(group));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO StudentsGroup (StudentsCount, GroupNumber, Course, CurriculumId)
|
||||||
|
VALUES (@StudentsCount, @GroupNumber, @Course, @CurriculumId)";
|
||||||
|
connection.Execute(queryInsert, group);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteGroup(int id)
|
public void DeleteGroup(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM StudentsGroup
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Group> ReadGroup()
|
public IEnumerable<StudentsGroup> ReadGroup()
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = "SELECT * FROM StudentsGroup";
|
||||||
|
var groups = connection.Query<StudentsGroup>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(groups));
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Group ReadGroupById(int id)
|
public StudentsGroup ReadGroupById(int id)
|
||||||
{
|
{
|
||||||
return Group.CreateGroup(0, 0, string.Empty, 0, 0);
|
_logger.LogInformation("Получение объекта по идентификатору");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var querySelect = @"
|
||||||
|
SELECT * FROM StudentsGroup
|
||||||
|
WHERE Id= @id";
|
||||||
|
var group = connection.QueryFirst<StudentsGroup>(querySelect, new { id });
|
||||||
|
_logger.LogDebug("Найденный объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(group));
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при поиске объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateGroup(Group group)
|
public void UpdateGroup(StudentsGroup group)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Редактирование объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(group));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryUpdate = @"
|
||||||
|
UPDATE StudentsGroup
|
||||||
|
SET
|
||||||
|
StudentsCount= @StudentsCount,
|
||||||
|
GroupNumber= @GroupNumber,
|
||||||
|
Course= @Course,
|
||||||
|
CurriculumId= @CurriculumId
|
||||||
|
WHERE Id= @Id";
|
||||||
|
connection.Execute(queryUpdate, group);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,75 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using Npgsql;
|
||||||
using System.Text;
|
using ProjectShedule.Entities;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.Repositories.Implementations;
|
||||||
public class SheduleRepository : ISheduleRepository
|
public class SheduleRepository : ISheduleRepository
|
||||||
{
|
{
|
||||||
|
private readonly IConnectionString _connectionString;
|
||||||
|
private readonly ILogger<SheduleRepository> _logger;
|
||||||
|
public SheduleRepository(IConnectionString connectionString, ILogger<SheduleRepository> logger)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
public void CreateShedule(Shedule shedule)
|
public void CreateShedule(Shedule shedule)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(shedule));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Shedule (Date, PairNumber, StudentsGroupId, TeacherId, SubjectId, ClassroomId)
|
||||||
|
VALUES (@Date, @PairNumber, @StudentsGroupId, @TeacherId, @SubjectId, @ClassroomId)";
|
||||||
|
connection.Execute(queryInsert, shedule);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteShedule(int id)
|
public void DeleteShedule(int id)
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Удаление объекта");
|
||||||
|
_logger.LogDebug("Объект: {id}", id);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryDelete = @"
|
||||||
|
DELETE FROM Shedule
|
||||||
|
WHERE Id=@id";
|
||||||
|
connection.Execute(queryDelete, new { id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при удалении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Shedule> ReadShedule(DateTime? dateTime = null, int? groupId = null)
|
public IEnumerable<Shedule> ReadShedule(DateTime? dateTime = null, int? groupId = null)
|
||||||
{
|
{
|
||||||
return [];
|
_logger.LogInformation("Получение всех объектов");
|
||||||
}
|
try
|
||||||
|
{
|
||||||
public void UpdateShedule(Shedule shedule)
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
{
|
var querySelect = "SELECT * FROM Shedule";
|
||||||
|
var shedule = connection.Query<Shedule>(querySelect);
|
||||||
|
_logger.LogDebug("Полученные объекты: {json}",
|
||||||
|
JsonConvert.SerializeObject(shedule));
|
||||||
|
return shedule;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,33 +1,119 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using Npgsql;
|
||||||
using System.Text;
|
using ProjectShedule.Entities;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.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 CreateSubject(Subject subject)
|
public void CreateSubject(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 IEnumerable<Subject> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Subject ReadSubjectById(int id)
|
public Subject ReadSubjectById(int id)
|
||||||
{
|
{
|
||||||
return Subject.CreateSubject(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,120 @@
|
|||||||
using ProjectShedule.Entities;
|
using Dapper;
|
||||||
using System;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Generic;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using Npgsql;
|
||||||
using System.Text;
|
using ProjectShedule.Entities;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectShedule.Repositories.Implementations;
|
namespace ProjectShedule.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("Добавление объекта");
|
||||||
|
_logger.LogDebug("Объект: {json}",
|
||||||
|
JsonConvert.SerializeObject(teacher));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
|
var queryInsert = @"
|
||||||
|
INSERT INTO Teacher (FirstName, LastName)
|
||||||
|
VALUES (@FirstName, @LastName)";
|
||||||
|
connection.Execute(queryInsert, teacher);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при добавлении объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteTeacher(int id)
|
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 IEnumerable<Teacher> ReadTeacher()
|
public IEnumerable<Teacher> ReadTeacher()
|
||||||
{
|
{
|
||||||
return [];
|
_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Teacher ReadTeacherById(int id)
|
public Teacher ReadTeacherById(int id)
|
||||||
{
|
{
|
||||||
return Teacher.CreateTeacher(0,string.Empty,string.Empty);
|
_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 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
|
||||||
|
FirstName = @FirstName,
|
||||||
|
LastName = @FirstName,
|
||||||
|
WHERE Id= @Id";
|
||||||
|
connection.Execute(queryUpdate, teacher);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка при редактировании объекта");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
ProjectShedule/ProjectShedule/appsettings.json
Normal file
15
ProjectShedule/ProjectShedule/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"Serilog": {
|
||||||
|
"Using": [ "Serilog.Sinks.File" ],
|
||||||
|
"MinimumLevel": "Debug",
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "File",
|
||||||
|
"Args": {
|
||||||
|
"path": "Logs/log.txt",
|
||||||
|
"rollingInterval": "Day"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user