* 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
54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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 MediaItemRepository : IMediaItemRepository
|
|
{
|
|
private readonly TvContext _dbContext;
|
|
|
|
public MediaItemRepository(TvContext dbContext) => _dbContext = dbContext;
|
|
|
|
public Task<Option<MediaItem>> Get(int id) =>
|
|
_dbContext.MediaItems
|
|
.Include(i => i.Source)
|
|
.SingleOrDefaultAsync(i => i.Id == id)
|
|
.Map(Optional);
|
|
|
|
public Task<List<MediaItem>> GetAll() => _dbContext.MediaItems.ToListAsync();
|
|
|
|
public Task<List<MediaItem>> Search(string searchString)
|
|
{
|
|
IQueryable<TelevisionEpisodeMediaItem> episodeData =
|
|
from c in _dbContext.TelevisionEpisodeMediaItems.Include(c => c.Source) select c;
|
|
|
|
if (!string.IsNullOrEmpty(searchString))
|
|
{
|
|
episodeData = episodeData.Where(c => EF.Functions.Like(c.Metadata.Title, $"%{searchString}%"));
|
|
}
|
|
|
|
IQueryable<MovieMediaItem> movieData =
|
|
from c in _dbContext.MovieMediaItems.Include(c => c.Source) select c;
|
|
|
|
if (!string.IsNullOrEmpty(searchString))
|
|
{
|
|
movieData = movieData.Where(c => EF.Functions.Like(c.Metadata.Title, $"%{searchString}%"));
|
|
}
|
|
|
|
return episodeData.OfType<MediaItem>().Concat(movieData.OfType<MediaItem>()).ToListAsync();
|
|
}
|
|
|
|
public async Task<bool> Update(MediaItem mediaItem)
|
|
{
|
|
_dbContext.MediaItems.Update(mediaItem);
|
|
return await _dbContext.SaveChangesAsync() > 0;
|
|
}
|
|
}
|
|
}
|