65 lines
1.9 KiB
C#
65 lines
1.9 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 async Task<Project> Get(int id)
|
|
{
|
|
using (DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
|
{
|
|
Project entity = await context.Projects.FirstOrDefaultAsync((e) => e.Id == id);
|
|
|
|
return entity;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<IEnumerable<Project>> GetAll()
|
|
{
|
|
using(DaSaSoDbContext context = _contextFactory.CreateDbContext())
|
|
{
|
|
IEnumerable<Project> entities = await context.Projects.ToListAsync();
|
|
return entities;
|
|
}
|
|
}
|
|
|
|
public async Task<Project> Update(int id, Project entity)
|
|
{
|
|
return await _nonQueryDataService.Update(id, entity);
|
|
}
|
|
|
|
public Project CreateNonAsync(Project entity)
|
|
{
|
|
return _nonQueryDataService.CreateNonAsync(entity);
|
|
}
|
|
}
|
|
}
|