diff --git a/StudentProgressRecord/Entity/Marks.cs b/StudentProgressRecord/Entity/Marks.cs index b54ec69..641d923 100644 --- a/StudentProgressRecord/Entity/Marks.cs +++ b/StudentProgressRecord/Entity/Marks.cs @@ -23,5 +23,6 @@ namespace StudentProgressRecord.Entity Mark = mark }; } + } } diff --git a/StudentProgressRecord/Entity/Statement.cs b/StudentProgressRecord/Entity/Statement.cs index a6ec764..6c7c009 100644 --- a/StudentProgressRecord/Entity/Statement.cs +++ b/StudentProgressRecord/Entity/Statement.cs @@ -17,7 +17,7 @@ namespace StudentProgressRecord.Entity public DateTime Date { get; set; } - public IEnumerable Marks { get; private set; } = []; + public IEnumerable Marks { get; set; } = []; public static Statement CreateOperation(long id, long subjectId, long teacherId, DateTime timeStamp, IEnumerable marks) diff --git a/StudentProgressRecord/Entity/StudentTransition.cs b/StudentProgressRecord/Entity/StudentTransition.cs index ed4f112..5e69af6 100644 --- a/StudentProgressRecord/Entity/StudentTransition.cs +++ b/StudentProgressRecord/Entity/StudentTransition.cs @@ -16,7 +16,7 @@ namespace StudentProgressRecord.Entity public Operations Operation { get; set; } - public DateTime TimeStamp { get; set; } + public DateTime Date { get; set; } public static StudentTransition CreateOperation(long id, long studentId, Operations operation, DateTime time) { @@ -25,7 +25,7 @@ namespace StudentProgressRecord.Entity Id = id, StudentId = studentId, Operation = operation, - TimeStamp = time + Date = time }; } } diff --git a/StudentProgressRecord/Entity/Subject.cs b/StudentProgressRecord/Entity/Subject.cs index 7b863ad..16598d6 100644 --- a/StudentProgressRecord/Entity/Subject.cs +++ b/StudentProgressRecord/Entity/Subject.cs @@ -20,7 +20,8 @@ namespace StudentProgressRecord.Entity return new Subject { Id = id, - Name = name + Name = name, + direction = direction }; } } diff --git a/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs b/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs index 305fd83..3cdd1f2 100644 --- a/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs +++ b/StudentProgressRecord/Forms/FormsEntity/FormStatement.Designer.cs @@ -61,6 +61,7 @@ // // dateTimePicker // + dateTimePicker.Enabled = false; dateTimePicker.Location = new Point(13, 163); dateTimePicker.Name = "dateTimePicker"; dateTimePicker.Size = new Size(250, 27); diff --git a/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs b/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs index 9c9956f..9ed164a 100644 --- a/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs +++ b/StudentProgressRecord/Forms/FormsEntity/FormStatement.cs @@ -35,9 +35,9 @@ namespace StudentProgressRecord.Forms var list = new List() {1,2,3,4,5}; + columnMark.ValueType = typeof(int); columnMark.DataSource = list; - - + columnStudent.DataSource = studentRepository.ReadStudents(); columnStudent.DisplayMember = "Name"; columnStudent.ValueMember = "Id"; @@ -47,7 +47,7 @@ namespace StudentProgressRecord.Forms { try { - if (dataGridView.RowCount < 1 || comboBoxTeacher.SelectedIndex < 0 || comboBoxSubject.SelectedIndex < 0) + if (dataGridView.RowCount < 2 || comboBoxTeacher.SelectedIndex < 0 || comboBoxSubject.SelectedIndex < 0) { throw new Exception("Имеются незаполненые поля"); } @@ -58,6 +58,7 @@ namespace StudentProgressRecord.Forms dateTimePicker.Value, CreateMarkListFromDataGrid()) ); + Close(); } catch (Exception ex) { diff --git a/StudentProgressRecord/Forms/FormsEntity/FormSubject.cs b/StudentProgressRecord/Forms/FormsEntity/FormSubject.cs index 8d26e36..5ceb3ac 100644 --- a/StudentProgressRecord/Forms/FormsEntity/FormSubject.cs +++ b/StudentProgressRecord/Forms/FormsEntity/FormSubject.cs @@ -62,7 +62,8 @@ namespace StudentProgressRecord { try { - if (string.IsNullOrWhiteSpace(textBoxSubject.Text) || checkedListBoxDir.Items.Count == 0) + if (string.IsNullOrWhiteSpace(textBoxSubject.Text) || + checkedListBoxDir.CheckedItems.Count == 0) { throw new Exception("Имя не может быть пустым"); } diff --git a/StudentProgressRecord/IRepositories/IConnectionString.cs b/StudentProgressRecord/IRepositories/IConnectionString.cs new file mode 100644 index 0000000..4dac8fe --- /dev/null +++ b/StudentProgressRecord/IRepositories/IConnectionString.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentProgressRecord.IRepositories +{ + public interface IConnectionString + { + string GetConnectionString(); + } +} diff --git a/StudentProgressRecord/Program.cs b/StudentProgressRecord/Program.cs index 2a73a6b..05ab2e7 100644 --- a/StudentProgressRecord/Program.cs +++ b/StudentProgressRecord/Program.cs @@ -1,9 +1,14 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; + using StudentProgressRecord.Forms; using StudentProgressRecord.IRepositories; using StudentProgressRecord.Repositories; using StudentProgressRecord.RepositoryImp; using Unity; using Unity.Lifetime; +using Unity.Microsoft.Logging; namespace StudentProgressRecord { @@ -23,6 +28,9 @@ namespace StudentProgressRecord { var container = new UnityContainer(); + container.AddExtension(new LoggingExtension(CreateLoggerFactory())); + + container.RegisterType(new SingletonLifetimeManager()); container.RegisterType (new TransientLifetimeManager()); @@ -42,5 +50,16 @@ namespace StudentProgressRecord return container; } + private static LoggerFactory CreateLoggerFactory() + { + var lf = new LoggerFactory(); + lf.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsetting.json") + .Build()) + .CreateLogger()); + return lf; + } } } \ No newline at end of file diff --git a/StudentProgressRecord/RepositoryImp/ConnectionString.cs b/StudentProgressRecord/RepositoryImp/ConnectionString.cs new file mode 100644 index 0000000..7f8264e --- /dev/null +++ b/StudentProgressRecord/RepositoryImp/ConnectionString.cs @@ -0,0 +1,18 @@ +using Microsoft.VisualBasic.ApplicationServices; +using StudentProgressRecord.IRepositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StudentProgressRecord.RepositoryImp +{ + public class ConnectionString : IConnectionString + { + public string GetConnectionString() + { + return "Server=localhost;Database=University;User Id=root;Password=password;"; + } + } +} diff --git a/StudentProgressRecord/RepositoryImp/StatementRepository.cs b/StudentProgressRecord/RepositoryImp/StatementRepository.cs index ec4736d..422c1f6 100644 --- a/StudentProgressRecord/RepositoryImp/StatementRepository.cs +++ b/StudentProgressRecord/RepositoryImp/StatementRepository.cs @@ -1,29 +1,106 @@ -using StudentProgressRecord.Entity; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgressRecord.Entity; +using StudentProgressRecord.IRepositories; using StudentProgressRecord.Repositories; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Data.SqlClient; + namespace StudentProgressRecord.RepositoryImp { public class StatementRepository : IStatementRepository { + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + + public StatementRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateStatement(Statement statement) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(statement)); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + connection.Open(); + + using var transaction = connection.BeginTransaction(); + + var queryInsert = @" + INSERT INTO Statement (SubjectId, TeacherId, Date) + VALUES (@SubjectId, @TeacherId, @Date); + SELECT MAX(Id) FROM Statement"; + + var statementID = connection.QueryFirst(queryInsert, statement, transaction); + + var querySubInsert = @" + INSERT INTO Marks (StatementId, StudentId, Mark) + VALUES (@StatementId, @StudentId,@Mark)"; + + foreach (var elem in statement.Marks) + { + connection.Execute(querySubInsert, new + { + statementID, + elem.StudentId, + elem.Mark + }, transaction); + } + transaction.Commit(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении объекта"); + throw; + } + } public void DeleteStatement(long id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryDelete = @" + DELETE FROM Statement + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public IEnumerable ReadStatements(long? subjectId = null, long? teacherId = null, DateTime? dateFrom = null, DateTime? dateTo = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = "SELECT * FROM Statement"; + var objs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(objs)); + return objs; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } } diff --git a/StudentProgressRecord/RepositoryImp/StudentRepository.cs b/StudentProgressRecord/RepositoryImp/StudentRepository.cs index a4ce0a1..a2e266a 100644 --- a/StudentProgressRecord/RepositoryImp/StudentRepository.cs +++ b/StudentProgressRecord/RepositoryImp/StudentRepository.cs @@ -1,4 +1,10 @@ -using StudentProgressRecord.Entity; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using Serilog.Core; +using StudentProgressRecord.Entity; +using StudentProgressRecord.IRepositories; using StudentProgressRecord.Repositories; using System; using System.Collections.Generic; @@ -10,29 +16,117 @@ namespace StudentProgressRecord.RepositoryImp { public class StudentRepository : IStudentRepository { + + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public StudentRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } public void CreateStudent(Student student) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект, {json}", JsonConvert.SerializeObject(student)); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var query = @" + INSERT INTO Student (Name, FamilyPos, Domitory) + VALUES (@Name, @FamilyPos, @Domitory)"; + connection.Execute(query, student); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении обЪекта"); + throw; + } } public void DeleteStudent(long id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryDelete = @" + DELETE FROM Student + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Student ReadStudentById(long id) { - return Student.CreateEntity(0, string.Empty, false , false); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = @" + SELECT * FROM Student + WHERE Id=@id"; + var obj = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(obj)); + return obj; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadStudents(bool? familyPos = null, bool? domitory = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = "SELECT * FROM Student"; + var objs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(objs)); + return objs; + } + 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.GetConnectionString()); + var queryUpdate = @" + UPDATE Student + SET + Name=@Name, + FamilyPos=@FamilyPos, + Domitory=@Domitory + WHERE Id=@Id"; + connection.Execute(queryUpdate, student); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } } } diff --git a/StudentProgressRecord/RepositoryImp/StudentTransitionRepository.cs b/StudentProgressRecord/RepositoryImp/StudentTransitionRepository.cs index ddec0cb..d54c6f6 100644 --- a/StudentProgressRecord/RepositoryImp/StudentTransitionRepository.cs +++ b/StudentProgressRecord/RepositoryImp/StudentTransitionRepository.cs @@ -1,28 +1,101 @@ using StudentProgressRecord.Entity; using StudentProgressRecord.IRepositories; using StudentProgressRecord.Entity.Enums; +using Newtonsoft.Json; +using Npgsql; +using Microsoft.Extensions.Logging; +using Dapper; namespace StudentProgressRecord.RepositoryImp { public class StudentTransitionRepository : IStudentTransitionRepository { + + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public StudentTransitionRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateStudentTransition(StudentTransition studentTransition) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект, {json}", JsonConvert.SerializeObject(studentTransition)); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var query = @" + INSERT INTO StudentTransition (StudentId, Operation, Date) + VALUES (@StudentId, @Operation, @Date)"; + connection.Execute(query, studentTransition); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении обЪекта"); + throw; + } } public void DeleteStudentTransition(long id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryDelete = @" + DELETE FROM StudentTransition + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public StudentTransition ReadStudentTransitionById(long id) { - return StudentTransition.CreateOperation(0, 0, Operations.Transfer, DateTime.Now); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = @" + SELECT * FROM StudentTransition + WHERE Id=@id"; + var obj = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(obj)); + return obj; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadStudentTransitions(long? groupId = null, bool? familyPos = null, bool? domitory = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = "SELECT * FROM StudentTransition"; + var objs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(objs)); + return objs; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } } } diff --git a/StudentProgressRecord/RepositoryImp/SubjectRepository.cs b/StudentProgressRecord/RepositoryImp/SubjectRepository.cs index 33dda91..b7487a9 100644 --- a/StudentProgressRecord/RepositoryImp/SubjectRepository.cs +++ b/StudentProgressRecord/RepositoryImp/SubjectRepository.cs @@ -1,39 +1,126 @@ -using StudentProgressRecord.Entity; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgressRecord.Entity; using StudentProgressRecord.Entity.Enums; +using StudentProgressRecord.IRepositories; using StudentProgressRecord.Repositories; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace StudentProgressRecord.RepositoryImp { public class SubjectRepository : ISubjectRepository { + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public SubjectRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + public void CreateSubject(Subject subject) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект, {json}", JsonConvert.SerializeObject(subject)); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var query = @" + INSERT INTO Subject (direction, Name) + VALUES (@direction ,@Name)"; + connection.Execute(query, subject); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении обЪекта"); + throw; + } } public void DeleteSubject(long id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryDelete = @" + DELETE FROM Subject + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Subject ReadSubjectById(long id) { - return Subject.CreateEntity(0, string.Empty, Direction.None); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = @" + SELECT * FROM Subject + WHERE Id=@id"; + var obj = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(obj)); + return obj; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadSubjects() { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = "SELECT * FROM Subject"; + var objs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(objs)); + return objs; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public void UpdateSubject(Subject subject) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(subject)); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryUpdate = @" + UPDATE Subject + SET + Name=@Name + WHERE Id=@Id"; + connection.Execute(queryUpdate, subject); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } } } } diff --git a/StudentProgressRecord/RepositoryImp/TeacherRepository.cs b/StudentProgressRecord/RepositoryImp/TeacherRepository.cs index 9ac1980..8fdc506 100644 --- a/StudentProgressRecord/RepositoryImp/TeacherRepository.cs +++ b/StudentProgressRecord/RepositoryImp/TeacherRepository.cs @@ -1,8 +1,14 @@ -using StudentProgressRecord.Entity; +using Dapper; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; +using Npgsql; +using StudentProgressRecord.Entity; +using StudentProgressRecord.IRepositories; using StudentProgressRecord.Repositories; using System; using System.Collections.Generic; using System.Linq; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; @@ -10,28 +16,118 @@ namespace StudentProgressRecord.RepositoryImp { public class TeacherRepository : ITeacherRepository { + + private readonly IConnectionString _connectionString; + private readonly ILogger _logger; + + public TeacherRepository(IConnectionString connectionString, ILogger logger) + { + _connectionString = connectionString; + _logger = logger; + } + + public void CreateTeacher(Teacher teacher) { - + _logger.LogInformation("Добавление объекта"); + _logger.LogDebug("Объект, {json}", JsonConvert.SerializeObject(teacher)); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var query = @" + INSERT INTO Teacher (Name) + VALUES (@Name)"; + connection.Execute(query, teacher); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при добавлении обЪекта"); + throw; + } } public void DeleteTeacher(long id) { - + _logger.LogInformation("Удаление объекта"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryDelete = @" + DELETE FROM Teacher + WHERE Id=@id"; + connection.Execute(queryDelete, new { id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при удалении объекта"); + throw; + } } public Teacher ReadTeacherById(long id) { - return Teacher.CreateEntity(0, string.Empty); + _logger.LogInformation("Получение объекта по идентификатору"); + _logger.LogDebug("Объект: {id}", id); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = @" + SELECT * FROM Teacher + WHERE Id=@id"; + var obj = connection.QueryFirst(querySelect, new { id }); + _logger.LogDebug("Найденный объект: {json}", + JsonConvert.SerializeObject(obj)); + return obj; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при поиске объекта"); + throw; + } } public IEnumerable ReadTeachers(long? departmentID = null) { - return []; + _logger.LogInformation("Получение всех объектов"); + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var querySelect = "SELECT * FROM Teacher"; + var objs = connection.Query(querySelect); + _logger.LogDebug("Полученные объекты: {json}", + JsonConvert.SerializeObject(objs)); + return objs; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при чтении объектов"); + throw; + } } public void UpdateTeacher(Teacher teacher) { + _logger.LogInformation("Редактирование объекта"); + _logger.LogDebug("Объект: {json}", + JsonConvert.SerializeObject(teacher)); + + try + { + using var connection = new NpgsqlConnection(_connectionString.GetConnectionString()); + var queryUpdate = @" + UPDATE Teacher + SET + Name=@Name + WHERE Id=@Id"; + connection.Execute(queryUpdate, teacher); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка при редактировании объекта"); + throw; + } + } } diff --git a/StudentProgressRecord/StudentProgressRecord.csproj b/StudentProgressRecord/StudentProgressRecord.csproj index 94297cd..126a7d2 100644 --- a/StudentProgressRecord/StudentProgressRecord.csproj +++ b/StudentProgressRecord/StudentProgressRecord.csproj @@ -9,9 +9,29 @@ + + + + + + Always + + + + + + + + + + + + + + @@ -29,4 +49,8 @@ + + + + \ No newline at end of file diff --git a/StudentProgressRecord/appsetting.json b/StudentProgressRecord/appsetting.json new file mode 100644 index 0000000..a13deda --- /dev/null +++ b/StudentProgressRecord/appsetting.json @@ -0,0 +1,15 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Debug", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/university_log.txt", + "rollingInterval": "Day" + } + } + ] + } +} \ No newline at end of file