diff --git a/StudentProgress/StudentProgress/FormStudentProgress.Designer.cs b/StudentProgress/StudentProgress/FormStudentProgress.Designer.cs index 8790753..9295e3b 100644 --- a/StudentProgress/StudentProgress/FormStudentProgress.Designer.cs +++ b/StudentProgress/StudentProgress/FormStudentProgress.Designer.cs @@ -48,7 +48,7 @@ menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Padding = new Padding(13, 5, 0, 5); - menuStrip1.Size = new Size(915, 48); + menuStrip1.Size = new Size(915, 46); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // @@ -56,7 +56,7 @@ // DirectoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { GroupsToolStripMenuItem, StudentsToolStripMenuItem, ProfessorsToolStripMenuItem, SubjectsToolStripMenuItem }); DirectoriesToolStripMenuItem.Name = "DirectoriesToolStripMenuItem"; - DirectoriesToolStripMenuItem.Size = new Size(184, 38); + DirectoriesToolStripMenuItem.Size = new Size(184, 36); DirectoriesToolStripMenuItem.Text = "Справочники"; // // GroupsToolStripMenuItem @@ -91,27 +91,27 @@ // OperationsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { GradesToolStripMenuItem, LecturesCountToolStripMenuItem }); OperationsToolStripMenuItem.Name = "OperationsToolStripMenuItem"; - OperationsToolStripMenuItem.Size = new Size(147, 38); + OperationsToolStripMenuItem.Size = new Size(147, 36); OperationsToolStripMenuItem.Text = "Операции"; // // GradesToolStripMenuItem // GradesToolStripMenuItem.Name = "GradesToolStripMenuItem"; - GradesToolStripMenuItem.Size = new Size(285, 44); + GradesToolStripMenuItem.Size = new Size(359, 44); GradesToolStripMenuItem.Text = "Оценки"; GradesToolStripMenuItem.Click += GradeToolStripMenuItem_Click; // // LecturesCountToolStripMenuItem // LecturesCountToolStripMenuItem.Name = "LecturesCountToolStripMenuItem"; - LecturesCountToolStripMenuItem.Size = new Size(285, 44); + LecturesCountToolStripMenuItem.Size = new Size(359, 44); LecturesCountToolStripMenuItem.Text = "Учет лекций"; LecturesCountToolStripMenuItem.Click += LecturesCountToolStripMenuItem_Click; // // ReportsToolStripMenuItem // ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; - ReportsToolStripMenuItem.Size = new Size(116, 38); + ReportsToolStripMenuItem.Size = new Size(116, 36); ReportsToolStripMenuItem.Text = "Отчеты"; // // FormStudentProgress @@ -126,7 +126,7 @@ Margin = new Padding(6, 7, 6, 7); Name = "FormStudentProgress"; StartPosition = FormStartPosition.CenterScreen; - Text = "Учет успеваемости студентов"; + Text = " "; menuStrip1.ResumeLayout(false); menuStrip1.PerformLayout(); ResumeLayout(false); diff --git a/StudentProgress/StudentProgress/Forms/FormSubjects.Designer.cs b/StudentProgress/StudentProgress/Forms/FormSubjects.Designer.cs index 8836a53..ef5306e 100644 --- a/StudentProgress/StudentProgress/Forms/FormSubjects.Designer.cs +++ b/StudentProgress/StudentProgress/Forms/FormSubjects.Designer.cs @@ -104,7 +104,7 @@ namespace StudentProgress.Forms Margin = new Padding(6, 6, 6, 6); Name = "FormSubjects"; Text = "Предметы"; - Load += FormSubjects__Load; + Load += FormSubjects_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/StudentProgress/StudentProgress/Forms/FormSubjects.cs b/StudentProgress/StudentProgress/Forms/FormSubjects.cs index c53ec9c..6c07d9c 100644 --- a/StudentProgress/StudentProgress/Forms/FormSubjects.cs +++ b/StudentProgress/StudentProgress/Forms/FormSubjects.cs @@ -2,7 +2,7 @@ using System.Windows.Forms; using StudentPerformance.Forms; using StudentProgress.Repositories; -using StudentProgress.Repositories.Implementations; +using Unity; namespace StudentProgress.Forms { @@ -10,13 +10,14 @@ namespace StudentProgress.Forms { private readonly ISubjectsRepository _subjectsRepository; - public FormSubjects(ISubjectsRepository subjectsRepository) + public FormSubjects() { InitializeComponent(); - _subjectsRepository = subjectsRepository ?? throw new ArgumentNullException(nameof(subjectsRepository)); + var container = Program.CreateContainer(); // Получаем контейнер Unity + _subjectsRepository = container.Resolve(); } - private void FormSubjects__Load(object sender, EventArgs e) + private void FormSubjects_Load(object sender, EventArgs e) { // Загрузка данных в DataGridView LoadData(); @@ -32,7 +33,7 @@ namespace StudentProgress.Forms private void buttonAdd_Click(object sender, EventArgs e) { // Логика добавления нового предмета - using (var form = new FormSubject(new SubjectsRepository())) + using (var form = new FormSubject(Program.CreateContainer().Resolve())) { if (form.ShowDialog() == DialogResult.OK) { diff --git a/StudentProgress/StudentProgress/Program.cs b/StudentProgress/StudentProgress/Program.cs index a264a2b..45f1fcb 100644 --- a/StudentProgress/StudentProgress/Program.cs +++ b/StudentProgress/StudentProgress/Program.cs @@ -1,9 +1,17 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; +using Unity; +using Unity.Lifetime; +using Serilog.Extensions.Logging; using StudentProgress.Forms; using StudentProgress.Repositories; using StudentProgress.Repositories.Implementations; using Unity; +using Unity.Microsoft.Logging; using System; using System.Windows.Forms; +using StudentPerformance.Repositories.Implementations; namespace StudentProgress { @@ -15,15 +23,28 @@ namespace StudentProgress Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + var container = CreateContainer(); + + Application.Run(container.Resolve()); + } + + public static UnityContainer CreateContainer() + { var container = new UnityContainer(); + // + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + + // + container.RegisterType(new SingletonLifetimeManager()); + // - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); - container.RegisterType(); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); // container.RegisterType(); @@ -31,10 +52,22 @@ namespace StudentProgress container.RegisterType(); container.RegisterType(); container.RegisterType(); - container.RegisterType(); - container.RegisterType(); + container.RegisterType(); + container.RegisterType(); - Application.Run(container.Resolve()); + 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; } } } \ No newline at end of file diff --git a/StudentProgress/StudentProgress/Repositories/IConnectionString.cs b/StudentProgress/StudentProgress/Repositories/IConnectionString.cs new file mode 100644 index 0000000..2d289e1 --- /dev/null +++ b/StudentProgress/StudentProgress/Repositories/IConnectionString.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentProgress.Repositories +{ + public interface IConnectionString + { + string ConnectionString { get; } + + } +} diff --git a/StudentProgress/StudentProgress/Repositories/ISubjectsRepository.cs b/StudentProgress/StudentProgress/Repositories/ISubjectsRepository.cs index d0c8d98..625111d 100644 --- a/StudentProgress/StudentProgress/Repositories/ISubjectsRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/ISubjectsRepository.cs @@ -4,7 +4,10 @@ namespace StudentProgress.Repositories; public interface ISubjectsRepository { - IEnumerable ReadSubjects(int? professorsNameId = null); void CreateSubjects_(Subjects subject); void DeleteSubjects(int id); -} \ No newline at end of file + IEnumerable ReadSubjects(int? id = null); + Subjects ReadSubjectById(int id); + void UpdateSubject(Subjects subject); +} + diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/ConnectionString.cs b/StudentProgress/StudentProgress/Repositories/Implementations/ConnectionString.cs new file mode 100644 index 0000000..8401f69 --- /dev/null +++ b/StudentProgress/StudentProgress/Repositories/Implementations/ConnectionString.cs @@ -0,0 +1,9 @@ +using StudentProgress.Repositories; + +namespace StudentProgress.Repositories.Implementations; + +public class ConnectionString : IConnectionString +{ + string IConnectionString.ConnectionString => + "Host=localhost;Port=5432;Database=studentperformancebd;Username=postgres;Password=Ildan12345;"; +} \ No newline at end of file diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/GradesRepository.cs b/StudentProgress/StudentProgress/Repositories/Implementations/GradesRepository.cs index 3cb0a6e..f0cacae 100644 --- a/StudentProgress/StudentProgress/Repositories/Implementations/GradesRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/Implementations/GradesRepository.cs @@ -1,29 +1,120 @@ -using StudentProgress.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using StudentProgress.Entities; +using StudentProgress.Repositories; using System; using System.Collections.Generic; +using System.Data.SqlClient; -namespace StudentProgress.Repositories.Implementations; - -public class GradesRepository : IGradesRepository +namespace StudentProgress.Repositories.Implementations { - public void CreateGrade(Grades grade) + public class GradesRepository : IGradesRepository { - // Логика создания оценки - } + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; - public void DeleteGrade(int id) - { - // Логика удаления оценки по идентификатору - } + public GradesRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } - public IEnumerable ReadGrades(DateTime? dateFrom = null, DateTime? dateTo = null, int? subjectsId = null, int? professorsId = null) - { - // Логика чтения оценок с возможностью фильтрации по дате, идентификатору предмета и идентификатору преподавателя - return new List(); - } + public void CreateGrade(Grades grade) + { + _logger.LogInformation("Добавление оценки"); + _logger.LogDebug("Оценка: {json}", JsonConvert.SerializeObject(grade)); + try + { + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = @" + INSERT INTO Grades (SubjectsId, ProfessorsId, Date) + VALUES (@SubjectsId, @ProfessorsId, @Date)"; + connection.Execute(query, grade); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении оценки"); + throw; + } + } - public void UpdateGrade(Grades grade) - { - // Логика обновления оценки + public void DeleteGrade(int id) + { + _logger.LogInformation("Удаление оценки"); + _logger.LogDebug("Оценка: {id}", id); + try + { + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = "DELETE FROM Grades WHERE Id = @Id"; + connection.Execute(query, new { Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении оценки"); + throw; + } + } + + public IEnumerable ReadGrades(DateTime? dateFrom = null, DateTime? dateTo = null, int? subjectsId = null, int? professorsId = null) + { + _logger.LogInformation("Получение оценок"); + try + { + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = "SELECT * FROM Grades"; + var parameters = new DynamicParameters(); + + if (dateFrom.HasValue) + { + query += " WHERE Date >= @DateFrom"; + parameters.Add("DateFrom", dateFrom.Value); + } + if (dateTo.HasValue) + { + query += " AND Date <= @DateTo"; + parameters.Add("DateTo", dateTo.Value); + } + if (subjectsId.HasValue) + { + query += " AND SubjectsId = @SubjectsId"; + parameters.Add("SubjectsId", subjectsId.Value); + } + if (professorsId.HasValue) + { + query += " AND ProfessorsId = @ProfessorsId"; + parameters.Add("ProfessorsId", professorsId.Value); + } + + var grades = connection.Query(query, parameters); + _logger.LogDebug("Полученные оценки: {json}", JsonConvert.SerializeObject(grades)); + return grades; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении оценок"); + throw; + } + } + + public void UpdateGrade(Grades grade) + { + _logger.LogInformation("Редактирование оценки"); + _logger.LogDebug("Оценка: {json}", JsonConvert.SerializeObject(grade)); + try + { + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = @" + UPDATE Grades + SET SubjectsId = @SubjectsId, ProfessorsId = @ProfessorsId, Date = @Date + WHERE Id = @Id"; + connection.Execute(query, grade); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании оценки"); + throw; + } + } } } \ No newline at end of file diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/GroupRepository.cs b/StudentProgress/StudentProgress/Repositories/Implementations/GroupRepository.cs index 0d147a2..4c6b383 100644 --- a/StudentProgress/StudentProgress/Repositories/Implementations/GroupRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/Implementations/GroupRepository.cs @@ -1,50 +1,127 @@ -using StudentProgress.Entities; -using System.Collections.Generic; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgress.Entities; +using StudentProgress.Repositories; -namespace StudentProgress.Repositories.Implementations +namespace StudentPerformance.Repositories.Implementations; + +public class GroupRepository : IGroupRepository { - public class GroupRepository : IGroupRepository + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + public GroupRepository(IConnectionString connectionString, ILogger logger) { - private readonly List _groups; + _connectionString = connectionString; + _logger = logger; + } - public GroupRepository() + public void CreateGroup(Group group) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(group)); + + try { - // Инициализация тестовых данных - _groups = new List(); + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @"INSERT INTO Groups (NameGroup, Course, NameFaculty) +VALUES (@NameGroup, @Course, @NameFaculty)"; + connection.Execute(queryInsert, group); } - - public void CreateGroup(Group group) + catch (Exception ex) { - // Логика создания группы - _groups.Add(group); - } - - public void DeleteGroup(int id) - { - // Логика удаления группы по идентификатору - _groups.RemoveAll(g => g.Id == id); - } - - public IEnumerable ReadGroup() - { - // Логика чтения всех групп - return _groups; - } - - public Group ReadGroupById(int id) - { - // Логика чтения группы по идентификатору - return _groups.Find(g => g.Id == id); - } - - public void UpdateGroup(Group group) - { - // Логика обновления группы - var existingGroup = _groups.Find(g => g.Id == group.Id); - if (existingGroup != null) - { - existingGroup.NameGroup = group.NameGroup; - } + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; } } -} \ No newline at end of file + + public void DeleteGroup(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Groups +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + + public IEnumerable ReadGroup() + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Groups"; + var groups = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(groups)); + return groups; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + + public Group ReadGroupById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Groups +WHERE Id=@id"; + var group = connection.QueryFirst(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(group)); + return group; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + + } + + public void UpdateGroup(Group group) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(group)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Groups +SET +NameGroup=@NameGroup, +Course=@Course, +NameFaculty=@NameFaculty +WHERE Id=@Id"; + connection.Execute(queryUpdate, group); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + + } +} diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/LecturesRepository.cs b/StudentProgress/StudentProgress/Repositories/Implementations/LecturesRepository.cs index c7d973f..9208019 100644 --- a/StudentProgress/StudentProgress/Repositories/Implementations/LecturesRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/Implementations/LecturesRepository.cs @@ -1,31 +1,76 @@ -using StudentProgress.Entities; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using StudentProgress.Entities; +using StudentProgress.Repositories; +using System; using System.Collections.Generic; -using System.Linq; +using System.Data.SqlClient; namespace StudentProgress.Repositories.Implementations { public class LecturesRepository : ILecturesRepository { - private readonly List _lectures = new List(); + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public LecturesRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public IEnumerable ReadLectures() { - return _lectures; + _logger.LogInformation("Получение лекций"); + try + { + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = "SELECT * FROM Lectures"; + var lectures = connection.Query(query); + _logger.LogDebug("Полученные лекции: {json}", JsonConvert.SerializeObject(lectures)); + return lectures; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении лекций"); + throw; + } } public void CreateLecture(Lectures lecture) { - int newLectureId = _lectures.Count > 0 ? _lectures.Max(l => l.LectureId) + 1 : 1; - lecture.SetLectureId(newLectureId); - _lectures.Add(lecture); + _logger.LogInformation("Добавление лекции"); + _logger.LogDebug("Лекция: {json}", JsonConvert.SerializeObject(lecture)); + try + { + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = @" + INSERT INTO Lectures (ProfessorId, Date, Auditorium) + VALUES (@ProfessorsId, @Date, @Auditorium)"; + connection.Execute(query, lecture); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении лекции"); + throw; + } } public void DeleteLecture(int lectureId) { - var lectureToRemove = _lectures.FirstOrDefault(l => l.LectureId == lectureId); - if (lectureToRemove != null) + _logger.LogInformation("Удаление лекции"); + _logger.LogDebug("Лекция: {id}", lectureId); + try { - _lectures.Remove(lectureToRemove); + using var connection = new SqlConnection(_connectionString.ConnectionString); + var query = "DELETE FROM Lectures WHERE LectureId = @LectureId"; + connection.Execute(query, new { LectureId = lectureId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении лекции"); + throw; } } } diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/ProfessorsNameRepository.cs b/StudentProgress/StudentProgress/Repositories/Implementations/ProfessorsNameRepository.cs index 1b5cbf4..66a920f 100644 --- a/StudentProgress/StudentProgress/Repositories/Implementations/ProfessorsNameRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/Implementations/ProfessorsNameRepository.cs @@ -1,34 +1,126 @@ -using StudentProgress.Entities; -using System.Collections.Generic; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgress.Entities; +using StudentProgress.Repositories; +using System.Data.SqlClient; namespace StudentProgress.Repositories.Implementations; public class ProfessorsNameRepository : IProfessorsNameRepository { + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public ProfessorsNameRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateProfessorsName(Professors professorsName) { - // Логика создания преподавателя + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(professorsName)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @"INSERT INTO ProfessorsName (FirstName, LastName, MiddleName, Classes) +VALUES (@FirstName, @LastName, @MiddleName, @Classes)"; + connection.Execute(queryInsert, professorsName); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } } public void DeleteProfessorsName(int id) { - // Логика удаления преподавателя по идентификатору + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM ProfessorsName +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public IEnumerable ReadProfessorsName() { - // Логика чтения всех преподавателей - return new List(); + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM ProfessorsName"; + var professorsNames = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(professorsNames)); + return professorsNames; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public Professors ReadProfessorsNameById(int id) { - // Логика чтения преподавателя по идентификатору - return Professors.CreateEntity(id, "Unknown", "Unknown"); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM ProfessorsName +WHERE Id=@id"; + var professorsName = connection.QueryFirst(querySelect, new { id }); + + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(professorsName)); + return professorsName; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public void UpdateProfessorsName(Professors professorsName) { - // Логика обновления преподавателя + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(professorsName)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" + UPDATE ProfessorsName +SET +FirstName=@FirstName, +LastName=@LastName, +MiddleName=@MiddleName, +Classes=@Classes +WHERE Id=@Id"; + connection.Execute(queryUpdate, professorsName); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } -} \ No newline at end of file +} diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/StudentRepository.cs b/StudentProgress/StudentProgress/Repositories/Implementations/StudentRepository.cs index 826e429..a0bb006 100644 --- a/StudentProgress/StudentProgress/Repositories/Implementations/StudentRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/Implementations/StudentRepository.cs @@ -1,56 +1,130 @@ -using StudentProgress.Entities; -using System.Collections.Generic; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgress.Entities; +using StudentProgress.Repositories; +using System.Data.SqlClient; -namespace StudentProgress.Repositories.Implementations +namespace StudentPerformance.Repositories.Implementations; + +public class StudentRepository : IStudentRepository { - public class StudentRepository : IStudentRepository + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public StudentRepository(IConnectionString connectionString, ILogger logger) { - private readonly List _students; + _connectionString = connectionString; + _logger = logger; + } - public StudentRepository() + public void CreateStudent(Student student) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(student)); + try { - // Инициализация пустого списка студентов - _students = new List(); + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryInsert = @" +INSERT INTO Student (FirstName, LastName, MiddleName, Phone, GroupID) +VALUES (@FirstName, @LastName, @MiddleName, @Phone, @GroupID)"; + connection.Execute(queryInsert, student); } - - public void CreateStudent(Student student) + catch (Exception ex) { - // Логика создания студента - _students.Add(student); - } - - public void DeleteStudent(int id) - { - // Логика удаления студента по идентификатору - _students.RemoveAll(s => s.Id == id); - } - - public Student ReadStudentById(int id) - { - // Логика чтения студента по идентификатору - return _students.Find(s => s.Id == id); - } - - public IEnumerable ReadStudents(int? groupID = null) - { - // Логика чтения всех студентов с возможностью фильтрации по идентификатору группы - if (groupID.HasValue) - { - return _students.FindAll(s => s.GroupId == groupID.Value); - } - return _students; - } - - public void UpdateStudent(Student student) - { - // Логика обновления студента - var existingStudent = _students.Find(s => s.Id == student.Id); - if (existingStudent != null) - { - existingStudent.Name = student.Name; - existingStudent.Surname = student.Surname; - existingStudent.GroupId = student.GroupId; - } + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; } } -} \ No newline at end of file + + public void DeleteStudent(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Student +WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + + public Student ReadStudentById(int id) + { + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = @" +SELECT * FROM Student +WHERE Id=@id"; + var student = connection.QueryFirst(querySelect, new + { + id + }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(student)); + return student; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + + public IEnumerable ReadStudents(int? groupID = null) + { + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var querySelect = "SELECT * FROM Student"; + var student = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(student)); + return student; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + + public void UpdateStudent(Student student) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(student)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryUpdate = @" +UPDATE Student +SET +FirstName=@FirstName, +LastName=@LastName, +MiddleName=@MiddleName, +Phone=@Phone, +GroupID=@GroupID +WHERE Id=@Id"; + connection.Execute(queryUpdate, student); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + } +} diff --git a/StudentProgress/StudentProgress/Repositories/Implementations/SubjectsRepository.cs b/StudentProgress/StudentProgress/Repositories/Implementations/SubjectsRepository.cs index bb88b56..5f77047 100644 --- a/StudentProgress/StudentProgress/Repositories/Implementations/SubjectsRepository.cs +++ b/StudentProgress/StudentProgress/Repositories/Implementations/SubjectsRepository.cs @@ -1,28 +1,186 @@ -using StudentProgress.Entities; -using System.Collections.Generic; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgress.Entities; -namespace StudentProgress.Repositories.Implementations; - -public class SubjectsRepository : ISubjectsRepository +namespace StudentProgress.Repositories.Implementations { - public void CreateSubjects(Subjects subject) + public class SubjectsRepository : ISubjectsRepository { - // Логика создания предмета - } + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; - public void CreateSubjects_(Subjects subject) - { - throw new NotImplementedException(); - } + public SubjectsRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } - public void DeleteSubjects(int id) - { - // Логика удаления предмета по идентификатору - } + // Добавление нового предмета + public void CreateSubjects_(Subjects subject) + { + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(subject)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + connection.Open(); + using var transaction = connection.BeginTransaction(); - public IEnumerable ReadSubjects(int? lecturerNameId = null) - { - // Логика чтения предметов с возможностью фильтрации по идентификатору преподавателя - return new List(); + var queryInsert = @" +INSERT INTO Subject (NameSubject) +VALUES (@NameSubject); +SELECT MAX(Id) FROM Subject"; + + // Выполняем запрос и получаем ID созданного предмета + var subjectId = connection.QueryFirst(queryInsert, subject, transaction); + + transaction.Commit(); + + _logger.LogInformation("Успешно добавлен объект с Id: {id}", subjectId); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } + + // Удаление предмета по идентификатору + public void DeleteSubjects(int id) + { + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + var queryDelete = @" +DELETE FROM Subject +WHERE Id=@Id"; + + var rowsAffected = connection.Execute(queryDelete, new { Id = id }); + + if (rowsAffected == 0) + { + _logger.LogWarning("Объект с Id: {id} не найден для удаления", id); + } + else + { + _logger.LogInformation("Объект с Id: {id} успешно удалён", id); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } + } + + // Получение всех предметов + public IEnumerable ReadSubjects(int? id = null) + { + _logger.LogInformation("Получение объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + + if (id.HasValue) + { + // Если указан ID, возвращаем конкретный предмет + var querySelectById = @" +SELECT * FROM Subject +WHERE Id = @Id"; + + var subject = connection.Query(querySelectById, new { Id = id.Value }).ToList(); + + if (!subject.Any()) + { + _logger.LogWarning("Объект с Id: {id} не найден", id); + } + else + { + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(subject)); + } + + return subject; + } + else + { + // Если ID не указан, возвращаем все предметы + var querySelectAll = @"SELECT * FROM Subject"; + + var subjects = connection.Query(querySelectAll).ToList(); + _logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(subjects)); + + return subjects; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } + } + + // Получение предмета по идентификатору + public Subjects ReadSubjectById(int id) + { + _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.QueryFirstOrDefault(querySelect, new { Id = id }); + + if (subject == null) + { + _logger.LogWarning("Объект с Id: {id} не найден", id); + } + else + { + _logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(subject)); + } + + return subject; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } + } + + // Обновление данных предмета + public void UpdateSubject(Subjects subject) + { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(subject)); + try + { + using var connection = new NpgsqlConnection(_connectionString.ConnectionString); + connection.Open(); + using var transaction = connection.BeginTransaction(); + + var queryUpdate = @" +UPDATE Subject +SET NameSubject = @NameSubject +WHERE Id = @Id"; + + connection.Execute(queryUpdate, subject, transaction); + transaction.Commit(); + + _logger.LogInformation("Объект с Id: {id} успешно обновлен", subject.Id); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + } } -} \ No newline at end of file +} diff --git a/StudentProgress/StudentProgress/StudentProgress.csproj b/StudentProgress/StudentProgress/StudentProgress.csproj index accbdf0..df12085 100644 --- a/StudentProgress/StudentProgress/StudentProgress.csproj +++ b/StudentProgress/StudentProgress/StudentProgress.csproj @@ -9,7 +9,20 @@ + + + + + + + + + + + + + diff --git a/StudentProgress/StudentProgress/appsettings.json b/StudentProgress/StudentProgress/appsettings.json new file mode 100644 index 0000000..0258958 --- /dev/null +++ b/StudentProgress/StudentProgress/appsettings.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "C:\\отп\\StudentProgress\\StudentProgress\\appsettings.json", + "rollingInterval": "Day" + } + } + ] + } +} diff --git a/StudentProgress/StudentProgress/appsettings20241204.com b/StudentProgress/StudentProgress/appsettings20241204.com new file mode 100644 index 0000000..bb0380d --- /dev/null +++ b/StudentProgress/StudentProgress/appsettings20241204.com @@ -0,0 +1,125 @@ +2024-12-04 18:12:04.577 +04:00 [INF] Получение групп +2024-12-04 18:12:05.492 +04:00 [ERR] Ошибка при чтении групп +System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. + at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 64 +2024-12-04 18:12:33.740 +04:00 [INF] Добавление группы +2024-12-04 18:12:34.889 +04:00 [DBG] Группа: {"Id":0,"NameGroup":"vhghg"} +2024-12-04 18:12:35.068 +04:00 [ERR] Ошибка при добавлении группы +System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. + at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GroupRepository.CreateGroup(Group group) in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 29 +2024-12-04 18:12:41.544 +04:00 [INF] Получение групп +2024-12-04 18:12:41.590 +04:00 [ERR] Ошибка при чтении групп +System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. + at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 64 +2024-12-04 18:14:45.539 +04:00 [INF] Получение групп +2024-12-04 18:14:45.623 +04:00 [ERR] Ошибка при чтении групп +System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. + at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 64 +2024-12-04 18:27:30.144 +04:00 [INF] Получение групп +2024-12-04 18:27:30.580 +04:00 [ERR] Ошибка при чтении групп +System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. + at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 64 +2024-12-04 18:40:36.369 +04:00 [INF] Получение групп +2024-12-04 18:40:37.721 +04:00 [ERR] Ошибка при чтении групп +System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. + at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 64 +2024-12-04 19:09:36.613 +04:00 [INF] Получение всех объектов +2024-12-04 19:09:37.378 +04:00 [ERR] Ошибка при чтении объектов +Npgsql.PostgresException (0x80004005): 3D000: database "studentperformancebd" does not exist + at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) + at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) + at Npgsql.Internal.NpgsqlConnector.g__OpenCore|214_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.g__RentAsync|33_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.Open() + at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1183 + at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) + at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) + at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 815 + at StudentPerformance.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 65 + Exception data: + Severity: FATAL + SqlState: 3D000 + MessageText: database "studentperformancebd" does not exist + File: postinit.c + Line: 1050 + Routine: InitPostgres +2024-12-04 19:48:23.173 +04:00 [INF] Получение всех объектов +2024-12-04 19:48:26.525 +04:00 [ERR] Ошибка при чтении объектов +Npgsql.PostgresException (0x80004005): 3D000: database "studentperformancebd" does not exist + at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) + at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) + at Npgsql.Internal.NpgsqlConnector.g__OpenCore|214_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.g__RentAsync|33_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.Open() + at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1183 + at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) + at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) + at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 815 + at StudentPerformance.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 65 + Exception data: + Severity: FATAL + SqlState: 3D000 + MessageText: database "studentperformancebd" does not exist + File: postinit.c + Line: 1050 + Routine: InitPostgres diff --git a/StudentProgress/StudentProgress/appsettings20241205.com b/StudentProgress/StudentProgress/appsettings20241205.com new file mode 100644 index 0000000..80454e1 --- /dev/null +++ b/StudentProgress/StudentProgress/appsettings20241205.com @@ -0,0 +1,105 @@ +2024-12-05 03:52:19.883 +04:00 [INF] Получение всех объектов +2024-12-05 03:52:20.333 +04:00 [ERR] Ошибка при чтении объектов +Npgsql.PostgresException (0x80004005): 3D000: database "studentperformancebd" does not exist + at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) + at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) + at Npgsql.Internal.NpgsqlConnector.g__OpenCore|214_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.g__RentAsync|33_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.Open() + at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1183 + at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) + at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) + at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 815 + at StudentPerformance.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 65 + Exception data: + Severity: FATAL + SqlState: 3D000 + MessageText: database "studentperformancebd" does not exist + File: postinit.c + Line: 1050 + Routine: InitPostgres +2024-12-05 03:52:31.028 +04:00 [INF] Получение оценок +2024-12-05 03:52:31.056 +04:00 [ERR] Ошибка при чтении оценок +System.ArgumentException: Keyword not supported: 'host'. + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GradesRepository.ReadGrades(Nullable`1 dateFrom, Nullable`1 dateTo, Nullable`1 subjectsId, Nullable`1 professorsId) in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GradesRepository.cs:line 64 +2024-12-05 03:52:40.306 +04:00 [INF] Получение оценок +2024-12-05 03:52:40.306 +04:00 [ERR] Ошибка при чтении оценок +System.ArgumentException: Keyword not supported: 'host'. + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.GradesRepository.ReadGrades(Nullable`1 dateFrom, Nullable`1 dateTo, Nullable`1 subjectsId, Nullable`1 professorsId) in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GradesRepository.cs:line 64 +2024-12-05 03:52:50.012 +04:00 [INF] Получение преподавателей +2024-12-05 03:52:50.013 +04:00 [ERR] Ошибка при чтении преподавателей +System.ArgumentException: Keyword not supported: 'host'. + at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey) + at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms) + at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) + at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) + at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) + at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) + at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) + at System.Data.SqlClient.SqlConnection..ctor(String connectionString) + at StudentProgress.Repositories.Implementations.ProfessorsNameRepository.ReadProfessorsName() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\ProfessorsNameRepository.cs:line 64 +2024-12-05 08:57:04.261 +04:00 [INF] Получение объектов +2024-12-05 08:57:05.030 +04:00 [ERR] Ошибка при чтении объектов +Npgsql.PostgresException (0x80004005): 3D000: database "studentperformancebd" does not exist + at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) + at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) + at Npgsql.Internal.NpgsqlConnector.g__OpenCore|214_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.g__RentAsync|33_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.Open() + at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1183 + at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) + at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) + at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 815 + at StudentProgress.Repositories.Implementations.SubjectsRepository.ReadSubjects(Nullable`1 id) in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\SubjectsRepository.cs:line 113 + Exception data: + Severity: FATAL + SqlState: 3D000 + MessageText: database "studentperformancebd" does not exist + File: postinit.c + Line: 1050 + Routine: InitPostgres +2024-12-05 12:31:25.485 +04:00 [INF] Получение всех объектов +2024-12-05 12:31:26.556 +04:00 [ERR] Ошибка при чтении объектов +Npgsql.PostgresException (0x80004005): 3D000: database "studentperformancebd" does not exist + at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) + at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) + at Npgsql.Internal.NpgsqlConnector.g__OpenCore|214_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.PoolingDataSource.g__RentAsync|33_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) + at Npgsql.NpgsqlConnection.Open() + at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1183 + at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) + at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) + at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 815 + at StudentPerformance.Repositories.Implementations.GroupRepository.ReadGroup() in C:\отп\StudentProgress\StudentProgress\Repositories\Implementations\GroupRepository.cs:line 65 + Exception data: + Severity: FATAL + SqlState: 3D000 + MessageText: database "studentperformancebd" does not exist + File: postinit.c + Line: 1050 + Routine: InitPostgres