using DaSaSo.Domain.Model; using DaSaSo.Domain.Services; using DaSaSo.EntityFramework.Services.Common; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DaSaSo.EntityFramework.Services { public class SewerObjectDataService : IDataService { private readonly DaSaSoDbContextFactory _contextFactory; private readonly NonQueryDataService _nonQueryDataService; public SewerObjectDataService(DaSaSoDbContextFactory contextFactory) { this._contextFactory = contextFactory; _nonQueryDataService = new NonQueryDataService(contextFactory); } public async Task Create(SewerObject entity) { return await _nonQueryDataService.Create(entity); } public SewerObject CreateNonAsync(SewerObject entity) { return _nonQueryDataService.CreateNonAsync(entity); } public async Task Delete(int id) { return await _nonQueryDataService.Delete(id); } public async Task Get(int id) { using (DaSaSoDbContext context = _contextFactory.CreateDbContext()) { SewerObject? s = await context.SewerObjects .Include("BuildingSite") .Include("PunktOben") .Include("PunktUnten") .Include("SewerDamages") .FirstOrDefaultAsync((e) => e.Id == id); return s; } } public Task> GetAll() { throw new NotImplementedException(); } public async Task> GetAllByBuildingsite(Buildingsite buildingsite) { int id = buildingsite.Id; using (DaSaSoDbContext context = _contextFactory.CreateDbContext()) { IEnumerable entities = await context.SewerObjects.Where(x => x.BuildingSite.Id == id).ToListAsync(); return entities; } } public async Task Update(int id, SewerObject entity) { return await _nonQueryDataService.Update(id, entity); } } }