Добавление должностей и клиентов
parent
fda7ac88ee
commit
4d0b4a63d2
|
|
@ -44,5 +44,68 @@ public class ClientRepository
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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<DatabaseConnection> connect)
|
||||||
|
{
|
||||||
|
connection = new MySqlConnection(connect.Value.ConnectionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Position> GetPositions()
|
||||||
|
{
|
||||||
|
List<Position> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue