shoc-backend/SeaHaven.DataServices/Implementation/CategoryDataService.cs
Alexandre Brandizzi 6bfb56f349 fix(data): stamp audit times in UTC and keep a caller-set work order creation time
WorkOrderDataService.AddAsync overwrote the UTC CreatedDate set by WorkOrderService with local server time, offsetting the SLA response clock on any host not running in UTC. Data services now stamp CreatedDate, LastModificationTime and DeletionTime with DateTime.UtcNow, and a work order keeps the creation time its caller set.
2026-09-25 12:04:40 -03:00

56 lines
1.6 KiB
C#

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<Category?> GetByIdAsync(int id)
{
return await _context.Categories.FindAsync(id);
}
public async Task<IEnumerable<Category>> GetAllAsync()
{
return await _context.Categories.ToListAsync();
}
public async Task<Category> AddAsync(Category category)
{
category.CreatedDate = DateTime.UtcNow;
await _context.Categories.AddAsync(category);
await _context.SaveChangesAsync();
return category;
}
public async Task UpdateAsync(Category category)
{
category.LastModificationTime = DateTime.UtcNow;
_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<bool> ExistsAsync(int id)
{
return await _context.Categories.AnyAsync(c => c.Id == id);
}
}
}