mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 09:33:13 +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.
100 lines
3 KiB
C#
100 lines
3 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
|
|
namespace SeaHaven.DataServices.Implementation
|
|
{
|
|
public class PMScheduleDataService : IPMScheduleDataService
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public PMScheduleDataService(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<PMSchedules?> GetByIdAsync(int id)
|
|
{
|
|
return await _context.PMSchedules.FindAsync(id);
|
|
}
|
|
|
|
public async Task<PMSchedules?> GetByIdWithDetailsAsync(int id)
|
|
{
|
|
return await _context.PMSchedules
|
|
.FirstOrDefaultAsync(p => p.Id == id);
|
|
}
|
|
|
|
public async Task<IEnumerable<PMSchedules>> GetAllAsync()
|
|
{
|
|
return await _context.PMSchedules.ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<PMSchedules>> GetAllWithDetailsAsync()
|
|
{
|
|
return await _context.PMSchedules
|
|
.Include(x => x.Asset)
|
|
.Include(x => x.Location)
|
|
.OrderByDescending(x => x.Id)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<PMSchedules>> GetByLocationIdAsync(int locationId)
|
|
{
|
|
return await _context.PMSchedules
|
|
.Where(p => p.LocationId == locationId)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<(IEnumerable<PMSchedules> Items, int TotalCount)> GetPagedAsync(
|
|
int page,
|
|
int pageSize,
|
|
string? search = null)
|
|
{
|
|
var query = _context.PMSchedules.AsQueryable();
|
|
|
|
var totalCount = await query.CountAsync();
|
|
var items = await query
|
|
.OrderBy(p => p.Id)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToListAsync();
|
|
|
|
return (items, totalCount);
|
|
}
|
|
|
|
public async Task<PMSchedules> AddAsync(PMSchedules schedule)
|
|
{
|
|
schedule.CreatedDate = DateTime.UtcNow;
|
|
await _context.PMSchedules.AddAsync(schedule);
|
|
await _context.SaveChangesAsync();
|
|
return schedule;
|
|
}
|
|
|
|
public async Task UpdateAsync(PMSchedules schedule)
|
|
{
|
|
schedule.LastModificationTime = DateTime.UtcNow;
|
|
_context.PMSchedules.Update(schedule);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task DeleteAsync(int id)
|
|
{
|
|
var entity = await GetByIdAsync(id);
|
|
if (entity != null)
|
|
{
|
|
_context.PMSchedules.Remove(entity);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
|
|
public async Task<bool> ExistsAsync(int id)
|
|
{
|
|
return await _context.PMSchedules.AnyAsync(p => p.Id == id);
|
|
}
|
|
|
|
public async Task<int> CountAsync()
|
|
{
|
|
return await _context.PMSchedules.CountAsync();
|
|
}
|
|
}
|
|
}
|