mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 09:33:13 +00:00
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
|
|
namespace SeaHaven.DataServices.Implementation
|
|
{
|
|
public class TaskListTemplateDataService : ITaskListTemplateDataService
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public TaskListTemplateDataService(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<TaskListTemplate?> GetByIdAsync(int id)
|
|
{
|
|
return await _context.TaskListTemplates.FindAsync(id);
|
|
}
|
|
|
|
public async Task<TaskListTemplate?> GetByIdWithItemsAsync(int id)
|
|
{
|
|
return await _context.TaskListTemplates
|
|
.Include(t => t.Items)
|
|
.FirstOrDefaultAsync(t => t.Id == id);
|
|
}
|
|
|
|
public async Task<IEnumerable<TaskListTemplate>> GetAllAsync()
|
|
{
|
|
return await _context.TaskListTemplates.ToListAsync();
|
|
}
|
|
|
|
public async Task<TaskListTemplate> AddAsync(TaskListTemplate template)
|
|
{
|
|
await _context.TaskListTemplates.AddAsync(template);
|
|
await _context.SaveChangesAsync();
|
|
return template;
|
|
}
|
|
|
|
public async Task UpdateAsync(TaskListTemplate template)
|
|
{
|
|
_context.TaskListTemplates.Update(template);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(int id)
|
|
{
|
|
var entity = await GetByIdAsync(id);
|
|
if (entity != null)
|
|
{
|
|
_context.TaskListTemplates.Remove(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
public async Task<bool> ExistsAsync(int id)
|
|
{
|
|
return await _context.TaskListTemplates.AnyAsync(t => t.Id == id);
|
|
}
|
|
}
|
|
}
|