From 4d0b4a63d29885a351c12ee66035741bb67c868f Mon Sep 17 00:00:00 2001 From: aaugust Date: Thu, 7 May 2026 11:18:04 +1000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=BB=D0=B6=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=B9=20=D0=B8=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/ClientRepository.cs | 63 +++++++++++++++++++ Database/PositionRepository.cs | 112 +++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 Database/PositionRepository.cs diff --git a/Database/ClientRepository.cs b/Database/ClientRepository.cs index d5deeec..62c4741 100644 --- a/Database/ClientRepository.cs +++ b/Database/ClientRepository.cs @@ -44,5 +44,68 @@ public class ClientRepository return result; } + public bool InsertClient(Client client) + { + string sql = "insert into `client` (`id`, `name`, `surname`) values (0, @name, @surname)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@name", client.Name); + command.Parameters.AddWithValue("@surname", client.Surname); + command.ExecuteNonQuery(); + } + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + public bool UpdateClient(Client client) + { + string sql = "update `client` set name = @name, surname = @surname"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@name", client.Name); + command.Parameters.AddWithValue("@surname", client.Surname); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool DeleteClient(Client client) + { + string sql = "delete from `client` where `id` = " + client.Id; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.ExecuteNonQuery(); + } + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } } \ No newline at end of file diff --git a/Database/PositionRepository.cs b/Database/PositionRepository.cs new file mode 100644 index 0000000..7b888bb --- /dev/null +++ b/Database/PositionRepository.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using BathHouseManagmet.Models; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace BathHouseManagmet.Database; + +public class PositionRepository +{ + MySqlConnection connection; + + public PositionRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + + public List GetPositions() + { + List result = new(); + string sql = "select * from position"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + result.Add(new Position + { + Id = reader.GetInt32("id"), + Name = reader.GetString("name"), + }); + } + } + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return result; + } + + public bool InsertPositon(Position position) + { + string sql = "insert into `position` (`id`, `name`) values (0, @name)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@id", position.Id); + command.Parameters.AddWithValue("@name", position.Name); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool UpdatePositon(Position position) + { + string sql = "insert into `position` (`id`, `name`) values (0, @name)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@id", position.Id); + command.Parameters.AddWithValue("@name", position.Name); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool DeletePositon(Position position) + { + string sql = "delete from `position` where `id` = " + position.Id; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } +} \ No newline at end of file