добавила сеты и почти реализовала хранилище клиента
This commit is contained in:
parent
f24716aee0
commit
e2035800e3
@ -1,13 +1,19 @@
|
|||||||
using System;
|
using BeautySalonDBModels.Models;
|
||||||
using System.Collections.Generic;
|
using Npgsql;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BeautySalonDBModels
|
namespace BeautySalonDBModels
|
||||||
{
|
{
|
||||||
public abstract class AbstractWorkWithStorage
|
public abstract class AbstractWorkWithStorage<T>
|
||||||
{
|
{
|
||||||
public abstract void AddClient(Clien);
|
public abstract void Add(T obj);
|
||||||
|
public abstract T? Remove(int id);
|
||||||
|
public abstract void Update(T obj);
|
||||||
|
public abstract List<T> GetObjects();
|
||||||
|
public abstract T? GetObject(int id);
|
||||||
|
|
||||||
|
public NpgsqlConnection GetConnection()
|
||||||
|
{
|
||||||
|
return new NpgsqlConnection("Host=localhost;Port=5555;Username=elina;Database=beauty_salon;Password=elina");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
69
BeautySalon/BeautySalonDBModels/Implements/ClientDB.cs
Normal file
69
BeautySalon/BeautySalonDBModels/Implements/ClientDB.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using BeautySalonDBModels.Models;
|
||||||
|
using Npgsql;
|
||||||
|
|
||||||
|
namespace BeautySalonDBModels.Implements
|
||||||
|
{
|
||||||
|
public class ClientDB : AbstractWorkWithStorage<Client>
|
||||||
|
{
|
||||||
|
public override void Add(Client client)
|
||||||
|
{
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO clients (fio, age) VALUES (@FIO, @Age)", conn);
|
||||||
|
cmd.Parameters.AddWithValue("@FIO", client.FIO);
|
||||||
|
cmd.Parameters.AddWithValue("@Age", client.Age);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Client? GetObject(int id)
|
||||||
|
{
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM clients WHERE client_id = {id}", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Client
|
||||||
|
{
|
||||||
|
ClientId = reader.GetInt32(0),
|
||||||
|
FIO = reader.GetString(1),
|
||||||
|
Age = reader.GetInt32(2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<Client> GetObjects()
|
||||||
|
{
|
||||||
|
var clients = new List<Client>();
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM clients order by id", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
clients.Add(new Client
|
||||||
|
{
|
||||||
|
ClientId = reader.GetInt32(0),
|
||||||
|
FIO = reader.GetString(1),
|
||||||
|
Age = reader.GetInt32(2)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Client? Remove(int id)
|
||||||
|
{
|
||||||
|
var client = GetObject(id);
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("delete from clients where client_id = {id}", conn);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(Client client)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,8 @@
|
|||||||
{
|
{
|
||||||
public class Cheque
|
public class Cheque
|
||||||
{
|
{
|
||||||
public int ChequeId { get; }
|
public int ChequeId { get; set; }
|
||||||
public int ClientId { get; }
|
public int ClientId { get; set; }
|
||||||
public int ReceptionId { get; }
|
public int ReceptionId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
{
|
{
|
||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
public int ClientId { get; }
|
public int ClientId { get; set; }
|
||||||
public string FIO { get; } = string.Empty;
|
public string FIO { get; set; } = string.Empty;
|
||||||
public int Age { get; }
|
public int Age { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
{
|
{
|
||||||
public class Master
|
public class Master
|
||||||
{
|
{
|
||||||
public int MasterId { get; }
|
public int MasterId { get; set; }
|
||||||
public int SpecialisationId { get; }
|
public int SpecialisationId { get; set; }
|
||||||
public string FIO { get; } = string.Empty;
|
public string FIO { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
{
|
{
|
||||||
public class Reception
|
public class Reception
|
||||||
{
|
{
|
||||||
public int ReceptionId { get; }
|
public int ReceptionId { get; set; }
|
||||||
public int MasterId { get; }
|
public int MasterId { get; set; }
|
||||||
public int ServiceId { get; }
|
public int ServiceId { get; set; }
|
||||||
public DateTime DateReception { get; }
|
public DateTime DateReception { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
{
|
{
|
||||||
public class Service
|
public class Service
|
||||||
{
|
{
|
||||||
public int ServiceId { get; }
|
public int ServiceId { get; set; }
|
||||||
public string ServiceName { get; } = string.Empty;
|
public string ServiceName { get; set; } = string.Empty;
|
||||||
public double Price { get; }
|
public double Price { get; set; }
|
||||||
public int SpecialisationId { get; }
|
public int SpecialisationId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
public class Specialisation
|
public class Specialisation
|
||||||
{
|
{
|
||||||
public int SpecialisationId { get; }
|
public int SpecialisationId { get; set; }
|
||||||
public string Name { get; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user