Kanalschaden werden richtig geparsed
This commit is contained in:
@@ -22,7 +22,7 @@ namespace DaSaSo.EntityFramework
|
||||
|
||||
public DaSaSoDbContext CreateDbContext()
|
||||
{
|
||||
DbContextOptionsBuilder<DaSaSoDbContext>? options = new DbContextOptionsBuilder<DaSaSoDbContext>();
|
||||
DbContextOptionsBuilder<DaSaSoDbContext>? options = new();
|
||||
_configureDbContext(options);
|
||||
//_connectionString = "Host = localhost; Database = dasaso; Username = kansan; Password = kansan";
|
||||
//options.UseNpgsql(_connectionString);
|
||||
@@ -34,7 +34,7 @@ namespace DaSaSo.EntityFramework
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<DaSaSoDbContext>();
|
||||
options.UseNpgsql("Host = localhost; Database = dasaso; Username = kansan; Password = kansan");
|
||||
DaSaSoDbContext result = new DaSaSoDbContext(options.Options);
|
||||
DaSaSoDbContext result = new(options.Options);
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -37,12 +37,10 @@ namespace DaSaSo.EntityFramework.Services
|
||||
|
||||
public async Task<Buildingsite> Get(int id)
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
Buildingsite entity = await context.Buildingsites.FirstOrDefaultAsync((e) => e.Id == id);
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
Buildingsite entity = await context.Buildingsites.FirstOrDefaultAsync((e) => e.Id == id);
|
||||
|
||||
return entity;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Task<IEnumerable<Buildingsite>> GetAll()
|
||||
@@ -54,11 +52,9 @@ namespace DaSaSo.EntityFramework.Services
|
||||
{
|
||||
// Get Clientid
|
||||
int id = project.Id;
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
IEnumerable<Buildingsite> entities = await context.Buildingsites.Where(x => x.Project.Id == id).ToListAsync();
|
||||
return entities;
|
||||
}
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
IEnumerable<Buildingsite> entities = await context.Buildingsites.Where(x => x.Project.Id == id).ToListAsync();
|
||||
return entities;
|
||||
}
|
||||
|
||||
public async Task<Buildingsite> Update(int id, Buildingsite entity)
|
||||
|
||||
@@ -39,22 +39,18 @@ namespace DaSaSo.EntityFramework.Services
|
||||
|
||||
public async Task<Client> Get(int id)
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
Client entity = await context.Clients.Include(a => a.Projects).FirstOrDefaultAsync((e) => e.Id == id);
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
Client entity = await context.Clients.Include(a => a.Projects).FirstOrDefaultAsync((e) => e.Id == id);
|
||||
|
||||
return entity;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Client>> GetAll()
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
IEnumerable<Client> entities = await context.Clients.ToListAsync();
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
IEnumerable<Client> entities = await context.Clients.ToListAsync();
|
||||
|
||||
return entities;
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
public async Task<Client> Update(int id, Client entity)
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -19,43 +20,35 @@ namespace DaSaSo.EntityFramework.Services.Common
|
||||
}
|
||||
public async Task<T> Create(T entity)
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
EntityEntry<T> createdEntity = await context.Set<T>().AddAsync(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return createdEntity.Entity;
|
||||
}
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
EntityEntry<T> createdEntity = await context.Set<T>().AddAsync(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return createdEntity.Entity;
|
||||
}
|
||||
|
||||
public T CreateNonAsync(T entity)
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
EntityEntry<T> createdEntity = context.Set<T>().Add(entity);
|
||||
context.SaveChanges();
|
||||
return createdEntity.Entity;
|
||||
}
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
EntityEntry<T> createdEntity = context.Set<T>().Add(entity);
|
||||
context.SaveChanges();
|
||||
return createdEntity.Entity;
|
||||
}
|
||||
|
||||
public async Task<bool> Delete(int id)
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
T entity = await context.Set<T>().FirstOrDefaultAsync((e) => e.Id == id);
|
||||
context.Set<T>().Remove(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
T entity = await context.Set<T>().FirstOrDefaultAsync((e) => e.Id == id);
|
||||
context.Set<T>().Remove(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
public async Task<T> Update(int id, T entity)
|
||||
{
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
entity.Id = id;
|
||||
context.Set<T>().Update(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return entity;
|
||||
}
|
||||
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
||||
entity.Id = id;
|
||||
context.Set<T>().Update(entity);
|
||||
await context.SaveChangesAsync();
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user