118 lines
4.3 KiB
C#
118 lines
4.3 KiB
C#
using Npgsql;
|
|
using SewerStammGen.Shared.Contracts;
|
|
using SewerStammGen.Shared.Domain;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SewerStammGen.DAL.Services.PostgresqlData
|
|
{
|
|
public class SchachtDataService : PostgresqlDataService, ISchachtDataService
|
|
{
|
|
public SchachtDataService(string connectionstring) : base(connectionstring,"schacht")
|
|
{
|
|
}
|
|
|
|
public async Task<Schacht> Create(Schacht entity)
|
|
{
|
|
string command = "INSERT INTO " + tableName + " (objektbezeichnung,rechtswert,hochwert,sohlhoehe,deckelhoehe,entwaesserung,ref_projekt_id) VALUES " +
|
|
"(@1,@2,@3,@4,@5,@6,@7) RETURNING schacht_id";
|
|
using(var cmd = new NpgsqlCommand(command,conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung);
|
|
cmd.Parameters.AddWithValue("2", entity.RechtsWert);
|
|
cmd.Parameters.AddWithValue("3", entity.HochWert);
|
|
cmd.Parameters.AddWithValue("4", entity.SohlHoehe);
|
|
cmd.Parameters.AddWithValue("5", entity.DeckelHoehe);
|
|
cmd.Parameters.AddWithValue("6", (int)entity.Entwaesserung);
|
|
cmd.Parameters.AddWithValue("7", entity.Projekt.Id);
|
|
using var reader = await cmd.ExecuteReaderAsync();
|
|
reader.Read();
|
|
entity.Id = reader.GetInt32(0);
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
public Task<Schacht> Get(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<IEnumerable<Schacht>> GetAll()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private Schacht parseSchacht(NpgsqlDataReader reader)
|
|
{
|
|
return new Schacht()
|
|
{
|
|
Id = reader.GetInt32(0),
|
|
Objektbezeichnung = reader.IsDBNull(1) ? "": reader.GetString(1),
|
|
RechtsWert = reader.GetDecimal(2),
|
|
HochWert = reader.GetDecimal(3),
|
|
SohlHoehe = reader.GetDecimal(4),
|
|
DeckelHoehe = reader.GetDecimal(5),
|
|
Entwaesserung = (EEntwaeserung)reader.GetInt32(6),
|
|
Projekt = new Projekt() { Id = reader.GetInt32(7) },
|
|
};
|
|
}
|
|
|
|
public async Task<IEnumerable<Schacht>> GetAllByProjekt(int projektID)
|
|
{
|
|
List<Schacht> result = new List<Schacht>();
|
|
string command = @"SELECT * FROM " + tableName + " WHERE ref_projekt_id = @1";
|
|
using (var cmd = new NpgsqlCommand(command, conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", projektID);
|
|
using (var reader = await cmd.ExecuteReaderAsync())
|
|
{
|
|
while(reader.Read())
|
|
{
|
|
result.Add(parseSchacht(reader));
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public async Task<IEnumerable<Schacht>> GetAllByProjekt(Projekt projekt)
|
|
{
|
|
return await GetAllByProjekt(projekt.Id);
|
|
}
|
|
|
|
public async Task<Schacht> Update(Schacht entity)
|
|
{
|
|
string command = @"UPDATE " + tableName + "SET " +
|
|
"objektbezeichnung=@1, rechtswert=@2, hochwert=@3, sohlhoehe=@4, deckelhoehe=@5, entwaesserung=@6, ref_projekt_id=@7 WHERE schacht_id=@8";
|
|
using(var cmd = new NpgsqlCommand(command,conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung);
|
|
cmd.Parameters.AddWithValue("2", entity.RechtsWert);
|
|
cmd.Parameters.AddWithValue("3", entity.HochWert);
|
|
cmd.Parameters.AddWithValue("4", entity.SohlHoehe);
|
|
cmd.Parameters.AddWithValue("5", entity.DeckelHoehe);
|
|
cmd.Parameters.AddWithValue("6", (int)entity.Entwaesserung);
|
|
cmd.Parameters.AddWithValue("7", entity.Projekt.Id);
|
|
cmd.Parameters.AddWithValue("8", entity.Id);
|
|
|
|
await cmd.ExecuteNonQueryAsync();
|
|
}
|
|
return entity;
|
|
|
|
}
|
|
|
|
public async Task<bool> InsertSchachtBulk(List<Schacht> schacht)
|
|
{
|
|
foreach(var item in schacht)
|
|
{
|
|
await Create(item);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|