Schacht können nun wieder gespeichert werden Converter um Schachttype erweitert.
138 lines
5.7 KiB
C#
138 lines
5.7 KiB
C#
using Npgsql;
|
|
using SewerStammGen.Shared.Contracts;
|
|
using SewerStammGen.Shared.Domain;
|
|
using SewerStammGen.Shared.Enum;
|
|
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,deckelrechtswert,deckelhochwert," +
|
|
"sohlrechtswert,sohlhochwert,sohlhoehe,deckelhoehe,entwaesserung,schachtype,vermesser,aufnahmedatum,ref_projekt_id) VALUES " +
|
|
"(@1,@2,@3,@4,@5,@6,@7,@8,@9,@10,@11,@12) RETURNING schacht_id";
|
|
using(var cmd = new NpgsqlCommand(command,conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung);
|
|
cmd.Parameters.AddWithValue("2", entity.DeckelRechtsWert);
|
|
cmd.Parameters.AddWithValue("3", entity.DeckelHochWert);
|
|
cmd.Parameters.AddWithValue("4", entity.SohlRechtsWert);
|
|
cmd.Parameters.AddWithValue("5", entity.SohlHochWert);
|
|
cmd.Parameters.AddWithValue("6", entity.SohlHoehe);
|
|
cmd.Parameters.AddWithValue("7", entity.DeckelHoehe);
|
|
cmd.Parameters.AddWithValue("8", (int)entity.Entwaesserung);
|
|
cmd.Parameters.AddWithValue("9", (int)entity.SchachtType);
|
|
cmd.Parameters.AddWithValue("10", entity.Vermesser);
|
|
cmd.Parameters.AddWithValue("11", entity.AufnahmeDatum);
|
|
cmd.Parameters.AddWithValue("12", 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),
|
|
DeckelRechtsWert = reader.GetDecimal(2),
|
|
DeckelHochWert = reader.GetDecimal(3),
|
|
DeckelHoehe = reader.GetDecimal(4),
|
|
SohlRechtsWert = reader.GetDecimal(5),
|
|
SohlHochWert = reader.GetDecimal(6),
|
|
SohlHoehe = reader.GetDecimal(7),
|
|
Entwaesserung = (EEntwaeserung)reader.GetInt32(8),
|
|
SchachtType = (ESchachtType)reader.GetInt32(9),
|
|
Vermesser = reader.GetString(10),
|
|
AufnahmeDatum = reader.GetString(11),
|
|
Projekt = new Projekt() { Id = reader.GetInt32(12) },
|
|
};
|
|
}
|
|
|
|
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)
|
|
{
|
|
// TODO: Typo in Schachtype beheben. Dies erfordert jedoch ein Datenbank updater Siehe Issue #7
|
|
string command = @"UPDATE " + tableName + " SET " +
|
|
"objektbezeichnung=@1, deckelrechtswert=@2, deckelhochwert=@3, deckelhoehe=@4, " +
|
|
"sohlrechtswert=@5, sohlhochwert=@6, sohlhoehe=@7, entwaesserung=@8, schachtype=@9, vermesser=@10, aufnahmedatum=@11, ref_projekt_id=@12 WHERE schacht_id=@13";
|
|
using(var cmd = new NpgsqlCommand(command,conn))
|
|
{
|
|
cmd.Parameters.AddWithValue("1", entity.Objektbezeichnung);
|
|
cmd.Parameters.AddWithValue("2", entity.DeckelRechtsWert);
|
|
cmd.Parameters.AddWithValue("3", entity.DeckelHochWert);
|
|
cmd.Parameters.AddWithValue("4", entity.DeckelHoehe);
|
|
cmd.Parameters.AddWithValue("5", entity.SohlRechtsWert);
|
|
cmd.Parameters.AddWithValue("6", entity.SohlHochWert);
|
|
cmd.Parameters.AddWithValue("7", entity.SohlHoehe);
|
|
cmd.Parameters.AddWithValue("8", (int)entity.Entwaesserung);
|
|
cmd.Parameters.AddWithValue("9", (int)entity.SchachtType);
|
|
cmd.Parameters.AddWithValue("10", entity.Vermesser);
|
|
cmd.Parameters.AddWithValue("11", entity.AufnahmeDatum);
|
|
cmd.Parameters.AddWithValue("12", entity.Projekt.Id);
|
|
cmd.Parameters.AddWithValue("13", 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;
|
|
}
|
|
}
|
|
}
|