62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using DaSaSo.Domain.Model;
|
|
using DaSaSo.Domain.Services;
|
|
using DaSaSo.EntityFramework.Services.Common;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DaSaSo.EntityFramework.Services
|
|
{
|
|
public class ClientDataService : IDataService<Client>
|
|
{
|
|
private readonly DaSaSoDbContextFactory _contextFactory;
|
|
private readonly NonQueryDataService<Client> _nonQueryDataService;
|
|
|
|
public ClientDataService(DaSaSoDbContextFactory contextFactory)
|
|
{
|
|
_contextFactory = contextFactory;
|
|
_nonQueryDataService = new NonQueryDataService<Client>(contextFactory);
|
|
}
|
|
|
|
public async Task<Client> Create(Client entity)
|
|
{
|
|
return await _nonQueryDataService.Create(entity);
|
|
}
|
|
|
|
public Client CreateNonAsync(Client entity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<bool> Delete(int id)
|
|
{
|
|
return await _nonQueryDataService.Delete(id);
|
|
}
|
|
|
|
public async Task<Client> Get(int id)
|
|
{
|
|
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
|
Client entity = await context.Clients.Include(a => a.Projects).FirstOrDefaultAsync((e) => e.Id == id);
|
|
|
|
return entity;
|
|
}
|
|
|
|
public async Task<IEnumerable<Client>> GetAll()
|
|
{
|
|
using DaSaSoDbContext context = _contextFactory.CreateDbContext();
|
|
IEnumerable<Client> entities = await context.Clients.ToListAsync();
|
|
|
|
return entities;
|
|
}
|
|
|
|
public async Task<Client> Update(int id, Client entity)
|
|
{
|
|
return await _nonQueryDataService.Update(id, entity);
|
|
}
|
|
}
|
|
}
|