using AutoMapper;
using ECMJobRunner.Domain.Entities;
using ECMJobRunner.Domain.Interfaces;
using ECMJobRunner.Infrastructure.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#if NET48
using System.Data.Entity;
#else
using Microsoft.EntityFrameworkCore;
#endif
namespace ECMJobRunner.Infrastructure.Repositories
{
///
/// CfgProfile repository implementation
///
public class CfgProfileRepository : Repository, ICfgProfileRepository
{
///
/// Constructor
///
public CfgProfileRepository(JobRunnerDbContext context, IMapper mapper) : base(context, mapper)
{
}
///
/// Gets a profile by ID with associated SQL jobs eagerly loaded
///
public async Task GetByIdWithSqlJobsAsync(long id, CancellationToken cancellationToken = default)
{
return await Context.CfgProfiles
.Include(p => p.SqlJobs)
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
}
///
/// Gets all active profiles with associated SQL jobs eagerly loaded
///
public async Task> GetAllActiveWithSqlJobsAsync(CancellationToken cancellationToken = default)
{
return await Context.CfgProfiles
.Include(p => p.SqlJobs)
.Where(p => p.Active)
.ToListAsync(cancellationToken);
}
}
}