73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SewerStammGen.EntityFramework.Services.Common;
|
|
using SewerStammGen.Shared.Contracts;
|
|
using Shared.Domain;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SewerStammGen.EntityFramework.Services
|
|
{
|
|
public class SchachtDataService : ISchachtDataService
|
|
{
|
|
private readonly SewerStammGenDbContextFactory _contextFactory;
|
|
private readonly NonQueryDataService<Schacht> _nonQueryDataService;
|
|
|
|
public SchachtDataService(SewerStammGenDbContextFactory contextFactory)
|
|
{
|
|
_contextFactory = contextFactory;
|
|
_nonQueryDataService = new NonQueryDataService<Schacht>(contextFactory);
|
|
}
|
|
|
|
public async Task<Schacht> Create(Schacht entity)
|
|
{
|
|
return await _nonQueryDataService.Create(entity);
|
|
}
|
|
|
|
public Schacht CreateNonAsync(Schacht entity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<bool> Delete(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<Schacht> Get(int id)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<IEnumerable<Schacht>> GetAll(int projektID)
|
|
{
|
|
using (SewerStammGenDbContext context = _contextFactory.CreateDbContext())
|
|
{
|
|
IEnumerable<Schacht> entities = await context.Set<Schacht>().Where(x => x.Projekt.Id.Equals(projektID)).ToListAsync();
|
|
return entities;
|
|
}
|
|
}
|
|
|
|
public Task<IEnumerable<Schacht>> GetAll()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<Schacht> GetSchachtByNameAndProjekt(string name, int projektID)
|
|
{
|
|
using(SewerStammGenDbContext context = _contextFactory.CreateDbContext())
|
|
{
|
|
Schacht entity = await context.Set<Schacht>().Where(x => x.Projekt.Id.Equals(projektID) && x.Objektbezeichnung.Equals(name)).FirstOrDefaultAsync();
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
public async Task<Schacht> Update(int id, Schacht entity)
|
|
{
|
|
return await _nonQueryDataService.Update(id, entity);
|
|
}
|
|
}
|
|
}
|