110 lines
3.8 KiB
C#
110 lines
3.8 KiB
C#
using Npgsql;
|
|
using SewerStammGen.Shared.Contracts;
|
|
using SewerStammGen.Shared.Domain;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SewerStammGen.DAL.Services.PostgresqlData
|
|
{
|
|
public class HaltungDataService : PostgresqlDataService, IHaltungDataService
|
|
{
|
|
public HaltungDataService(string connectionstring) : base(connectionstring, "Kanaele")
|
|
{
|
|
}
|
|
|
|
public Task<Kanal> Create(Kanal entity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<Kanal> Get(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<IEnumerable<Kanal>> GetAll()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<IEnumerable<Kanal>> GetAllByProjekt(int projektID)
|
|
{
|
|
List<Kanal> result = new List<Kanal>();
|
|
ISchachtDataService schachtDataService = new SchachtDataService(connString);
|
|
IEnumerable<Schacht> schaechte = await schachtDataService.GetAllByProjekt(projektID);
|
|
|
|
string command = "SELECT * FROM " + tableName + " WHERE \"ProjektId\" = @1";
|
|
using (var cmd = new NpgsqlCommand(command, conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", projektID);
|
|
using (var reader = await cmd.ExecuteReaderAsync())
|
|
{
|
|
while(reader.Read())
|
|
{
|
|
Kanal adding = parseHaltung(reader);
|
|
|
|
adding.StartSchacht = schaechte.Where(x => x.Id == reader.GetInt32(2)).Last();
|
|
adding.EndSchacht = schaechte.Where(x => x.Id == reader.GetInt32(3)).Last();
|
|
result.Add(adding);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
|
|
}
|
|
|
|
private Kanal parseHaltung(NpgsqlDataReader reader)
|
|
{
|
|
return new Kanal()
|
|
{
|
|
Id = reader.GetInt32(0),
|
|
Objektbezeichnung = reader.GetString(1),
|
|
//StartSchacht = reader.GetInt32(2),
|
|
//EndSchacht = reader.GetInt32(3),
|
|
DN = reader.GetInt32(4),
|
|
Material = reader.GetString(5),
|
|
Haltungslaenge = reader.GetDecimal(6),
|
|
Entwaesserung = (EEntwaeserung)reader.GetInt32(7),
|
|
Projekt = new Projekt() { Id = reader.GetInt32(8) }
|
|
};
|
|
}
|
|
|
|
public async Task<IEnumerable<Kanal>> GetAllByProjekt(Projekt projekt)
|
|
{
|
|
return await GetAllByProjekt(projekt.Id);
|
|
}
|
|
|
|
public async Task<Kanal> Update(Kanal entity)
|
|
{
|
|
|
|
string command = "UPDATE " + tableName + " SET " +
|
|
" \"Objektbezeichnung\"=@1, " +
|
|
" \"StartSchachtId\"=@2, " +
|
|
" \"EndSchachtId\"=@3, " +
|
|
" \"DN\"=@4, " +
|
|
" \"Material\"=@5, " +
|
|
" \"Haltungslaenge\"=@6, " +
|
|
" \"Entwaesserung\"=@7 " +
|
|
" WHERE \"Id\" = @8";
|
|
using(var cmd = new NpgsqlCommand(command,conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung);
|
|
cmd.Parameters.AddWithValue("2", entity.StartSchacht.Id);
|
|
cmd.Parameters.AddWithValue("3", entity.EndSchacht.Id);
|
|
cmd.Parameters.AddWithValue("4", entity.DN);
|
|
cmd.Parameters.AddWithValue("5", entity.Material);
|
|
cmd.Parameters.AddWithValue("6", entity.Haltungslaenge);
|
|
cmd.Parameters.AddWithValue("7", (int)entity.Entwaesserung);
|
|
cmd.Parameters.AddWithValue("8", entity.Id);
|
|
|
|
await cmd.ExecuteNonQueryAsync();
|
|
}
|
|
return entity;
|
|
}
|
|
}
|
|
}
|