constellation-api/CH.CQRS/Query/EnergyRate/EnergyRateQueryAll.cs

47 lines
1.4 KiB
C#

using CH.Dal;
using CH.Enum;
using Microsoft.EntityFrameworkCore;
namespace CH.CQRS.Query.EnergyRate;
public class EnergyRateQueryAll
{
}
public class EnergyRateQueryAllItem
{
public long Id { get; set; }
public long? ProviderId { get; set; }
public required string Name { get; set; }
public decimal? Rate { get; set; }
public bool Active { get; set; }
public Currency Currency { get; set; }
public DateTime? DisabledAt { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
}
public class EnergyRateAllQueryableProvider(CHDbContext dbContext) : IQueryableProviderOverride<EnergyRateQueryAllItem>
{
public async Task<IQueryable<EnergyRateQueryAllItem>> GetQueryableAsync(object query, CancellationToken cancellationToken = default)
{
var queryable = dbContext.EnergyRates
.AsNoTracking()
.AsQueryable();
var result = queryable
.Select(energyRate => new EnergyRateQueryAllItem
{
Id = energyRate.Id,
ProviderId = energyRate.ProviderId,
Name = energyRate.Name,
Rate = energyRate.Rate,
Active = energyRate.Active,
Currency = energyRate.Currency,
DisabledAt = energyRate.DisabledAt,
CreatedAt = energyRate.CreatedAt,
UpdatedAt = energyRate.UpdatedAt
})
.OrderBy(energyRate => energyRate.Name);
return result;
}
}