50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
using Distribution.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Distribution.Features.DriverProfile;
|
|
|
|
public class DriverProfileRepository(AppDBContext context) : IDriverProfileRepository
|
|
{
|
|
public async Task<global::Distribution.Models.DriverProfile?> GetByIdAsync(Guid id) =>
|
|
await context.DriverProfiles
|
|
.Include(p => p.User)
|
|
.FirstOrDefaultAsync(p => p.Id == id);
|
|
|
|
public async Task<global::Distribution.Models.DriverProfile?> GetByUserIdAsync(Guid userId) =>
|
|
await context.DriverProfiles
|
|
.Include(p => p.User)
|
|
.FirstOrDefaultAsync(p => p.FK_UserId == userId);
|
|
|
|
public async Task<List<global::Distribution.Models.DriverProfile>> GetAllAsync(int page, int pageSize) =>
|
|
await context.DriverProfiles
|
|
.Include(p => p.User)
|
|
.Where(p => p.IsActive)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToListAsync();
|
|
|
|
public async Task<int> GetCountAsync() =>
|
|
await context.DriverProfiles.CountAsync(p => p.IsActive);
|
|
|
|
public async Task AddAsync(global::Distribution.Models.DriverProfile profile) =>
|
|
await context.DriverProfiles.AddAsync(profile);
|
|
|
|
public void Update(global::Distribution.Models.DriverProfile profile) =>
|
|
context.DriverProfiles.Update(profile);
|
|
|
|
public void Deactivate(global::Distribution.Models.DriverProfile profile)
|
|
{
|
|
profile.IsActive = false;
|
|
context.DriverProfiles.Update(profile);
|
|
}
|
|
|
|
public async Task<global::Distribution.Models.DriverComplianceConfig?> GetComplianceConfigAsync() =>
|
|
await context.DriverComplianceConfigs.FirstOrDefaultAsync();
|
|
|
|
public async Task AddComplianceConfigAsync(global::Distribution.Models.DriverComplianceConfig config) =>
|
|
await context.DriverComplianceConfigs.AddAsync(config);
|
|
|
|
public void UpdateComplianceConfig(global::Distribution.Models.DriverComplianceConfig config) =>
|
|
context.DriverComplianceConfigs.Update(config);
|
|
}
|