Files
DaSaSo/DaSaSo.EntityFramework/Services/ProjectDataService.cs
2021-09-15 19:12:31 +02:00

61 lines
1.8 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 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);
}
}
}