From 55e84ef57c6abfe4ef4f4ef588ea91f719ce8536 Mon Sep 17 00:00:00 2001 From: aaugust Date: Mon, 11 May 2026 08:59:25 +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=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B5=D0=B2=20=D0=B4=D0=BE=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=86=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/DiscountRepository.cs | 118 ++++++++++++++++ Database/OrderRepository.cs | 130 ++++++++++++++++++ Database/PositionRepository.cs | 5 +- Database/ZoneRepository.cs | 110 +++++++++++++++ Models/Discount.cs | 2 +- .../net10.0/BathHouseManagmet.AssemblyInfo.cs | 2 +- ...BathHouseManagmet.AssemblyInfoInputs.cache | 2 +- 7 files changed, 363 insertions(+), 6 deletions(-) create mode 100644 Database/DiscountRepository.cs create mode 100644 Database/OrderRepository.cs create mode 100644 Database/ZoneRepository.cs diff --git a/Database/DiscountRepository.cs b/Database/DiscountRepository.cs new file mode 100644 index 0000000..7cc9cd1 --- /dev/null +++ b/Database/DiscountRepository.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using BathHouseManagmet.Models; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace BathHouseManagmet.Database; + +public class DiscountRepository +{ + MySqlConnection connection; + + public DiscountRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + + public List GetDiscounts() + { + List result = new(); + string sql = "select * from `discount`"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + result.Add(new Discount + { + Id = reader.GetInt32("id"), + Name = reader.GetString("name"), + Description = reader.GetString("description"), + DiscountPercent = reader.GetInt32("discount_percent") + }); + } + } + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return result; + } + + public bool InsertDiscount(Discount discount) + { + string sql = + "insert into `discount` (`id`, `name`, `description`, `discount_percent`) values (0, @name, @description, @discount_percent)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@id", discount.Id); + command.Parameters.AddWithValue("@name", discount.Name); + command.Parameters.AddWithValue("@description", discount.Description); + command.Parameters.AddWithValue("@discount_percent", discount.DiscountPercent); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return false; + } + + public bool UpdateDiscount(Discount discount) + { + string sql = + "update `discount` set name = @name, description = @description, discount_percent = @discount_percent"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@id", discount.Id); + command.Parameters.AddWithValue("@name", discount.Name); + command.Parameters.AddWithValue("@description", discount.Description); + command.Parameters.AddWithValue("@discount_percent", discount.DiscountPercent); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return false; + } + + public bool DeleteDiscount(Discount discount) + { + string sql = "delete from `discount` where `id` = " + discount.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 diff --git a/Database/OrderRepository.cs b/Database/OrderRepository.cs new file mode 100644 index 0000000..4fe6c48 --- /dev/null +++ b/Database/OrderRepository.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using BathHouseManagmet.Models; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace BathHouseManagmet.Database; + +public class OrderRepository +{ + MySqlConnection connection; + + public OrderRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + + public List GetOrders() + { + List result = new(); + string sql = "select * from orders"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + result.Add(new Order + { + Id = reader.GetInt32("id"), + ClientId = reader.GetInt32("client_id"), + ZoneId = reader.GetInt32("zone_id"), + OrderDate = reader.GetDateTime("order_date"), + WorkPrice = reader.GetInt32("work_price"), + EmployeeId = reader.GetInt32("employee_id"), + DiscountId = reader.GetInt32("discount_id"), + FinalPrice = reader.GetInt32("final_price"), + }); + } + } + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return result; + } + + public bool InsertOrder(Order order) + { + string sql = + "insert into `order` (`id`, `client_id`, `zone_id`, `order_date`, `work_price`, `employee_id`, `discount_id`, `final_price`) values (0, @client_id, @client_id, @zone_id, @order_date, @work_price, @employee_id, @discount_id, @final_price)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@client_id", order.ClientId); + command.Parameters.AddWithValue("@zone_id", order.ZoneId); + command.Parameters.AddWithValue("@order_date", order.OrderDate); + command.Parameters.AddWithValue("@work_price", order.WorkPrice); + command.Parameters.AddWithValue("@employee_id", order.EmployeeId); + command.Parameters.AddWithValue("@discount_id", order.DiscountId); + command.Parameters.AddWithValue("@final_price", order.FinalPrice); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool UpdateOrder(Order order) + { + string sql = + "update `order` set client_id = @client_id, zone_id = @zone_id, order_date = @order_date, work_price = @work_price, employee_id = @employee_id, discount_id = @discount_id, final_price = @final_price"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@client_id", order.ClientId); + command.Parameters.AddWithValue("@zone_id", order.ZoneId); + command.Parameters.AddWithValue("@order_date", order.OrderDate); + command.Parameters.AddWithValue("@work_price", order.WorkPrice); + command.Parameters.AddWithValue("@employee_id", order.EmployeeId); + command.Parameters.AddWithValue("@discount_id", order.DiscountId); + command.Parameters.AddWithValue("@final_price", order.FinalPrice); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool DeleteOrder(Order order) + { + string sql = "delete from `order` where `id` = " + order.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 diff --git a/Database/PositionRepository.cs b/Database/PositionRepository.cs index 7b888bb..d365887 100644 --- a/Database/PositionRepository.cs +++ b/Database/PositionRepository.cs @@ -18,7 +18,7 @@ public class PositionRepository public List GetPositions() { List result = new(); - string sql = "select * from position"; + string sql = "select * from `position`"; try { connection.Open(); @@ -68,13 +68,12 @@ public class PositionRepository public bool UpdatePositon(Position position) { - string sql = "insert into `position` (`id`, `name`) values (0, @name)"; + string sql = "update `position` set name = @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(); } diff --git a/Database/ZoneRepository.cs b/Database/ZoneRepository.cs new file mode 100644 index 0000000..2883894 --- /dev/null +++ b/Database/ZoneRepository.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using BathHouseManagmet.Models; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace BathHouseManagmet.Database; + +public class ZoneRepository +{ + MySqlConnection connection; + + public ZoneRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + + public List GetZones() + { + List result = new(); + string sql = "select * from zone"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + result.Add(new Zone + { + Id = reader.GetInt32("id"), + Name = reader.GetString("name"), + }); + } + } + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return result; + } + + public bool InsertZone(Zone zone) + { + string sql = "insert into `zone` (`id`, `name`) values (0, @name)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@name", zone.Name); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool UpdateZone(Zone zone) + { + string sql = "update `zone` set name = @name"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@name", zone.Name); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool DeleteZone(Zone zone) + { + string sql = "delete from `zone` where id = " + zone.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 diff --git a/Models/Discount.cs b/Models/Discount.cs index 0a0dc32..86740db 100644 --- a/Models/Discount.cs +++ b/Models/Discount.cs @@ -5,5 +5,5 @@ public class Discount public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } - public int DescountPercent { get; set; } + public int DiscountPercent { get; set; } } \ No newline at end of file diff --git a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs index a311175..88e348a 100644 --- a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs +++ b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("BathHouseManagmet")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9c2351b863396c43a39f9449f08dc29f85df9763")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4d0b4a63d29885a351c12ee66035741bb67c868f")] [assembly: System.Reflection.AssemblyProductAttribute("BathHouseManagmet")] [assembly: System.Reflection.AssemblyTitleAttribute("BathHouseManagmet")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache index 03d5ef9..372a912 100644 --- a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache +++ b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache @@ -1 +1 @@ -4757971917ac4d5bc9219094abbbd12816220e52e18e259e295afe360fad1005 +00710766fbaba364e5f0fd3c7dc3d271457e9a7b5c0166076f7bdc3704b53eb6