using Data.SeaHavenIndustries; using Microsoft.EntityFrameworkCore; using SeaHaven.DataServices.Interfaces; namespace SeaHaven.DataServices.Implementation { public class CategoryDataService : ICategoryDataService { private readonly ApplicationDbContext _context; public CategoryDataService(ApplicationDbContext context) { _context = context; } public async Task GetByIdAsync(int id) { return await _context.Categories.FindAsync(id); } public async Task> GetAllAsync() { return await _context.Categories.ToListAsync(); } public async Task AddAsync(Category category) { category.CreatedDate = DateTime.Now; await _context.Categories.AddAsync(category); await _context.SaveChangesAsync(); return category; } public async Task UpdateAsync(Category category) { category.LastModificationTime = DateTime.Now; _context.Categories.Update(category); await _context.SaveChangesAsync(); } public async Task DeleteAsync(int id) { var entity = await GetByIdAsync(id); if (entity != null) { _context.Categories.Remove(entity); await _context.SaveChangesAsync(); } } public async Task ExistsAsync(int id) { return await _context.Categories.AnyAsync(c => c.Id == id); } } }