добавила реализацию приема (Receptions)
This commit is contained in:
parent
f59bac0c58
commit
1498d5b7b7
83
BeautySalon/BeautySalonDBModels/Implements/ReceptionBD.cs
Normal file
83
BeautySalon/BeautySalonDBModels/Implements/ReceptionBD.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using BeautySalonDBModels.Models;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonDBModels.Implements
|
||||
{
|
||||
public class ReceptionBD : AbstractWorkWithStorage<Reception>
|
||||
{
|
||||
public override void Add(Reception reception)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("INSERT INTO receptions (master_id, service_id, date_reception) " +
|
||||
"VALUES (@MasterId, @ServiceId, @DateReception)", conn);
|
||||
cmd.Parameters.AddWithValue("@MasterId", reception.MasterId);
|
||||
cmd.Parameters.AddWithValue("@ServiceId", reception.ServiceId);
|
||||
cmd.Parameters.AddWithValue("@DateReception", reception.DateReception);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public override Reception? GetObject(int id)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM receptions WHERE reception_id = {id}", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
if (reader.Read())
|
||||
{
|
||||
return new Reception
|
||||
{
|
||||
ReceptionId = reader.GetInt32(0),
|
||||
MasterId = reader.GetInt32(1),
|
||||
ServiceId = reader.GetInt32(2),
|
||||
DateReception = reader.GetDateTime(3)
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override List<Reception> GetObjects()
|
||||
{
|
||||
var receptions = new List<Reception>();
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("SELECT * FROM receptions order by reception_id", conn);
|
||||
using var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
receptions.Add(new Reception
|
||||
{
|
||||
ReceptionId = reader.GetInt32(0),
|
||||
MasterId = reader.GetInt32(1),
|
||||
ServiceId = reader.GetInt32(2),
|
||||
DateReception = reader.GetDateTime(3)
|
||||
});
|
||||
}
|
||||
return receptions;
|
||||
}
|
||||
|
||||
public override Reception? Remove(int id)
|
||||
{
|
||||
var reception = GetObject(id);
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("delete from receptions where reception_id = {id}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
return reception;
|
||||
}
|
||||
|
||||
public override void Update(Reception reception)
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("update reception set master_id = {reception.MasterId}, " +
|
||||
"service_id = {reception.ServiceId}, date_reception = {reception.DateReception} where reception_id = {reception.ReceptionId}", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user