SchachtDataService hinzugefügt
This commit is contained in:
109
SewerStammGen.DAL/Services/PostgresqlData/SchachtDataService.cs
Normal file
109
SewerStammGen.DAL/Services/PostgresqlData/SchachtDataService.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
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,"Schaechte")
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<Schacht> Create(Schacht entity)
|
||||
{
|
||||
string command = "INSERT INTO " + tableName + " (\"Objektbezeichnung\",\"RechtsWert\",\"HochWert\",\"SohlHoehe\",\"DeckelHoehe\",\"Entwaesserung\",\"ProjektId\") VALUES " +
|
||||
"(@1,@2,@3,@4,@5,@6,@7) RETURNING \"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 \"ProjektId\" = @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," +
|
||||
" \"ProjektId\"=@7 WHERE \"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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user