* rework television media * refactor poster saving * television and movie views are working again * remove dead code * use paper styling for all cards * add show poster, plot to seasons page * remove missing shows; cleanup interfaces * fix split show display (same show in different folders/sources) * add placeholder "add to schedule" button * no more duplicate television shows, even with the same show split across sources * stop releasing CLI for now * use season number as season placeholder * add television shows to collections * add television seasons to collections * add television episodes to collections * add movies to collections * remove movies, shows, seasons, episodes from collections * fix page width and menus * fix buffer size defaults * fix chronological episode ordering * allow deleting media collections * don't get stuck building a playout with an empty collection * schedule editing and playouts work again * minor cleanup * remove dead code * fix bugs with viewing movies as they are loading * add scanner tests; support nested movie folders * update collections docs * rearrange order of schedule items * add show and season to schedule * delete schedules that use legacy collections, reset all posters * move cleanup to new migration * load fallback metadata when nfo fails; don't require metadata in ui * update readme and screenshots
72 lines
2.9 KiB
C#
72 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using LanguageExt;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using static LanguageExt.Prelude;
|
|
|
|
namespace ErsatzTV.Infrastructure.Data.Repositories
|
|
{
|
|
public class ProgramScheduleRepository : IProgramScheduleRepository
|
|
{
|
|
private readonly TvContext _dbContext;
|
|
|
|
public ProgramScheduleRepository(TvContext dbContext) => _dbContext = dbContext;
|
|
|
|
public async Task<ProgramSchedule> Add(ProgramSchedule programSchedule)
|
|
{
|
|
await _dbContext.ProgramSchedules.AddAsync(programSchedule);
|
|
await _dbContext.SaveChangesAsync();
|
|
return programSchedule;
|
|
}
|
|
|
|
public Task<Option<ProgramSchedule>> Get(int id) =>
|
|
_dbContext.ProgramSchedules.SingleOrDefaultAsync(s => s.Id == id).Map(Optional);
|
|
|
|
public async Task<Option<ProgramSchedule>> GetWithPlayouts(int id) =>
|
|
await _dbContext.ProgramSchedules
|
|
.Include(ps => ps.Items)
|
|
.Include(ps => ps.Playouts)
|
|
.SingleOrDefaultAsync(ps => ps.Id == id);
|
|
|
|
public Task<List<ProgramSchedule>> GetAll() =>
|
|
_dbContext.ProgramSchedules.ToListAsync();
|
|
|
|
public async Task Update(ProgramSchedule programSchedule)
|
|
{
|
|
_dbContext.ProgramSchedules.Update(programSchedule);
|
|
await _dbContext.SaveChangesAsync();
|
|
await _dbContext.Entry(programSchedule).Collection(s => s.Items).Query().Include(i => i.MediaCollection)
|
|
.LoadAsync();
|
|
await _dbContext.Entry(programSchedule).Collection(s => s.Playouts).LoadAsync();
|
|
}
|
|
|
|
public async Task Delete(int programScheduleId)
|
|
{
|
|
ProgramSchedule programSchedule = await _dbContext.ProgramSchedules.FindAsync(programScheduleId);
|
|
_dbContext.ProgramSchedules.Remove(programSchedule);
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
public async Task<Option<List<ProgramScheduleItem>>> GetItems(int programScheduleId)
|
|
{
|
|
Option<ProgramSchedule> maybeSchedule = await Get(programScheduleId);
|
|
return await maybeSchedule.Map(
|
|
async programSchedule =>
|
|
{
|
|
await _dbContext.Entry(programSchedule).Collection(s => s.Items).LoadAsync();
|
|
await _dbContext.Entry(programSchedule).Collection(s => s.Items).Query()
|
|
.Include(i => i.MediaCollection)
|
|
.Include(i => i.TelevisionShow)
|
|
.ThenInclude(s => s.Metadata)
|
|
.Include(i => i.TelevisionSeason)
|
|
.ThenInclude(s => s.TelevisionShow)
|
|
.ThenInclude(s => s.Metadata)
|
|
.LoadAsync();
|
|
return programSchedule.Items;
|
|
}).Sequence();
|
|
}
|
|
}
|
|
}
|