Добавление репозиториев до конца

master
Святой Владислав Солоп 2026-05-11 08:59:25 +10:00
parent 4d0b4a63d2
commit 55e84ef57c
7 changed files with 363 additions and 6 deletions

View File

@ -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<DatabaseConnection> connect)
{
connection = new MySqlConnection(connect.Value.ConnectionString);
}
public List<Discount> GetDiscounts()
{
List<Discount> 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;
}
}

130
Database/OrderRepository.cs Normal file
View File

@ -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<DatabaseConnection> connect)
{
connection = new MySqlConnection(connect.Value.ConnectionString);
}
public List<Order> GetOrders()
{
List<Order> 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;
}
}

View File

@ -18,7 +18,7 @@ public class PositionRepository
public List<Position> GetPositions()
{
List<Position> 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();
}

110
Database/ZoneRepository.cs Normal file
View File

@ -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<DatabaseConnection> connect)
{
connection = new MySqlConnection(connect.Value.ConnectionString);
}
public List<Zone> GetZones()
{
List<Zone> 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;
}
}

View File

@ -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; }
}

View File

@ -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")]

View File

@ -1 +1 @@
4757971917ac4d5bc9219094abbbd12816220e52e18e259e295afe360fad1005
00710766fbaba364e5f0fd3c7dc3d271457e9a7b5c0166076f7bdc3704b53eb6