66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
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 BuildingsiteDataService : IDataService<Buildingsite>
|
|
{
|
|
private readonly DaSaSoDbContextFactory _contextFactory;
|
|
private readonly NonQueryDataService<Buildingsite> _nonQueryDataService;
|
|
|
|
public BuildingsiteDataService(DaSaSoDbContextFactory contextFactory)
|
|
{
|
|
_contextFactory = contextFactory;
|
|
_nonQueryDataService = new NonQueryDataService<Buildingsite>(contextFactory);
|
|
}
|
|
public async Task<Buildingsite> Create(Buildingsite entity)
|
|
{
|
|
return await _nonQueryDataService.Create(entity);
|
|
}
|
|
|
|
public Buildingsite CreateNonAsync(Buildingsite entity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<bool> Delete(int id)
|
|
{
|
|
return await _nonQueryDataService.Delete(id);
|
|
}
|
|
|
|
public async Task<Buildingsite> Get(int id)
|
|
{
|
|
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
|
Buildingsite entity = await context.Buildingsites.FirstOrDefaultAsync((e) => e.Id == id);
|
|
|
|
return entity;
|
|
}
|
|
|
|
public Task<IEnumerable<Buildingsite>> GetAll()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<IEnumerable<Buildingsite>> GetAllByProjekt(Project project)
|
|
{
|
|
// 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;
|
|
}
|
|
|
|
public async Task<Buildingsite> Update(int id, Buildingsite entity)
|
|
{
|
|
return await _nonQueryDataService.Update(id, entity);
|
|
}
|
|
}
|
|
}
|