mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 17:43:12 +00:00
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.
56 lines
1.6 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|