52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using Koogle.Domain.Interfaces;
|
|
using Koogle.Infrastructure.Data;
|
|
using KoogleApp.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
|
|
namespace Koogle.Infrastructure.Repositories;
|
|
|
|
public class DayRepository : Repository<Day>, IDayRepository
|
|
{
|
|
//private readonly ILogger<IDayRepository> _logger;
|
|
//private readonly IDbContextFactory<ApplicationDbContext> _contextFactory;
|
|
|
|
public DayRepository(IDbContextFactory<ApplicationDbContext> contextFactory) : base(contextFactory)
|
|
{
|
|
|
|
}
|
|
|
|
public async Task<List<Day>> GetAllAsync(int year)
|
|
{
|
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
|
var res = await context.Days
|
|
.Where(_ => _.PostDate >= new DateTime(year, 1, 1) && _.PostDate <= new DateTime(year, 12, 31))
|
|
.ToListAsync();
|
|
return res;
|
|
}
|
|
|
|
public async Task<Day?> GetActiveDayAsync()
|
|
{
|
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
|
var res = await context.Days.FirstOrDefaultAsync(_ => _.PostDate == DateTime.Today);
|
|
return res;
|
|
}
|
|
|
|
//public async Task<Day> AddAsync(Day day)
|
|
//{
|
|
// await using var context = await ContextFactory.CreateDbContextAsync();
|
|
// var res = await context.Days.AddAsync(day);
|
|
// await context.SaveChangesAsync();
|
|
// return day;
|
|
//}
|
|
|
|
//public async Task<Day> UpdateAsync(Day day)
|
|
//{
|
|
// await using var context = await ContextFactory.CreateDbContextAsync();
|
|
// var res = context.Days.Update(day);
|
|
// await context.SaveChangesAsync();
|
|
// return res.Entity;
|
|
//}
|
|
}
|