добавила реализацию специализации
This commit is contained in:
parent
ca5288a1c4
commit
1eef200c11
@ -0,0 +1,77 @@
|
|||||||
|
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 SpecialisationDB : AbstractWorkWithStorage<Specialisation>
|
||||||
|
{
|
||||||
|
public override void Add(Specialisation specialisation)
|
||||||
|
{
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO specialisations (specialisation_name) " +
|
||||||
|
"VALUES (@Name)", conn);
|
||||||
|
cmd.Parameters.AddWithValue("@Name", specialisation.Name);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Specialisation? GetObject(int id)
|
||||||
|
{
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM specialisations WHERE specialisation_id = {id}", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Specialisation
|
||||||
|
{
|
||||||
|
SpecialisationId = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<Specialisation> GetObjects()
|
||||||
|
{
|
||||||
|
var specialisations = new List<Specialisation>();
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM specialisations order by specialisation_id", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
specialisations.Add(new Specialisation
|
||||||
|
{
|
||||||
|
SpecialisationId = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return specialisations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Specialisation? Remove(int id)
|
||||||
|
{
|
||||||
|
var specialisation = GetObject(id);
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("delete from specialisations where specialisation_id = {id}", conn);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return specialisation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(Specialisation specialisation)
|
||||||
|
{
|
||||||
|
using var conn = GetConnection();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("update specialisation set specialisation_name = {specialisation.Name}, " +
|
||||||
|
"where specialisation_id = {specialisation.SpecialisationId}", conn);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user