Commands auf Async umgestellt
This commit is contained in:
60
DaSaSo.EntityFramework/Services/ProjectDataService.cs
Normal file
60
DaSaSo.EntityFramework/Services/ProjectDataService.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
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 ProjectDataService : IDataService<Project>
|
||||
{
|
||||
private readonly DaSaSoDbContextFactory _contextFactory;
|
||||
private readonly NonQueryDataService<Project> _nonQueryDataService;
|
||||
|
||||
public ProjectDataService(DaSaSoDbContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
_nonQueryDataService = new NonQueryDataService<Project>(contextFactory);
|
||||
}
|
||||
|
||||
public async Task<Project> Create(Project entity)
|
||||
{
|
||||
return await _nonQueryDataService.Create(entity);
|
||||
}
|
||||
|
||||
public async Task<bool> Delete(int id)
|
||||
{
|
||||
return await _nonQueryDataService.Delete(id);
|
||||
}
|
||||
|
||||
public Task<Project> Get(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Project>> GetAllByClient(Client client)
|
||||
{
|
||||
// Get Clientid
|
||||
int id = client.Id;
|
||||
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
||||
{
|
||||
IEnumerable<Project> entities = await context.Projects.Where(x => x.Client.Id == id).ToListAsync();
|
||||
return entities;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<IEnumerable<Project>> GetAll()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Project> Update(int id, Project entity)
|
||||
{
|
||||
return await _nonQueryDataService.Update(id, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user