SchachtDataService hinzugefügt
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
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 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 Task<Kanal> Update(Kanal entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user