Grundlegene Funktionen geschrieben
This commit is contained in:
75
dcnsanplanung.DAL/Services/PostgresqlData/LVDataService.cs
Normal file
75
dcnsanplanung.DAL/Services/PostgresqlData/LVDataService.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using dcnsanplanung.shared.Model;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace dcnsanplanung.DAL.Services.PostgresqlData
|
||||
{
|
||||
public class LVDataService : PostgresqlDataService
|
||||
{
|
||||
public LVDataService(string connectionstring) : base(connectionstring, "leistungsverzeichnisposition")
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<LeistungsverzeichnisPosition> Create(LeistungsverzeichnisPosition entity)
|
||||
{
|
||||
string command = "INSERT INTO " + tableName + " (guid, positionsnummer, titel, einheit) VALUES " +
|
||||
"(@1,@2,@3,@4) RETURNING id";
|
||||
using (var cmd = new NpgsqlCommand(command, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("1", entity.Guid.ToString());
|
||||
cmd.Parameters.AddWithValue("2", entity.Positionsnummer);
|
||||
cmd.Parameters.AddWithValue("3", entity.Titel);
|
||||
cmd.Parameters.AddWithValue("4", entity.Einheit);
|
||||
using var reader = await cmd.ExecuteReaderAsync();
|
||||
reader.Read();
|
||||
entity.ID = reader.GetInt32(0);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LeistungsverzeichnisPosition>> GetAll()
|
||||
{
|
||||
List<LeistungsverzeichnisPosition> result = new List<LeistungsverzeichnisPosition>();
|
||||
string command = "SELECT * FROM " + tableName + ";";
|
||||
using (var cmd = new NpgsqlCommand(command, conn))
|
||||
{
|
||||
using (var reader = await cmd.ExecuteReaderAsync())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
LeistungsverzeichnisPosition adding = parsePosition(reader);
|
||||
|
||||
result.Add(adding);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private LeistungsverzeichnisPosition parsePosition(NpgsqlDataReader reader)
|
||||
{
|
||||
LeistungsverzeichnisPosition result = new LeistungsverzeichnisPosition()
|
||||
{
|
||||
ID = reader.GetInt32(0),
|
||||
Guid = Guid.Parse(reader.GetString(1)),
|
||||
Positionsnummer = reader.GetString(2),
|
||||
Titel = reader.GetString(3),
|
||||
Einheit = reader.GetString(4)
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> InsertLeistungsverzeichnisPositionBulk(List<LeistungsverzeichnisPosition> position)
|
||||
{
|
||||
foreach (var item in position)
|
||||
{
|
||||
await Create(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user