mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.1 KiB
54 lines
2.1 KiB
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.LibraryPath) |
|
.OrderBy(i => i.Id) |
|
.SingleOrDefaultAsync(i => i.Id == id) |
|
.Map(Optional); |
|
|
|
public Task<List<MediaItem>> GetAll() => _dbContext.MediaItems.ToListAsync(); |
|
|
|
public Task<List<MediaItem>> Search(string searchString) => |
|
// TODO: fix this when we need to search |
|
// IQueryable<TelevisionEpisodeMediaItem> episodeData = |
|
// from c in _dbContext.TelevisionEpisodeMediaItems.Include(c => c.LibraryPath) select c; |
|
// |
|
// if (!string.IsNullOrEmpty(searchString)) |
|
// { |
|
// episodeData = episodeData.Where(c => EF.Functions.Like(c.Metadata.Title, $"%{searchString}%")); |
|
// } |
|
// |
|
// IQueryable<Movie> movieData = |
|
// from c in _dbContext.Movies.Include(c => c.LibraryPath) 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(); |
|
new List<MediaItem>().AsTask(); |
|
|
|
public async Task<bool> Update(MediaItem mediaItem) |
|
{ |
|
_dbContext.MediaItems.Update(mediaItem); |
|
return await _dbContext.SaveChangesAsync() > 0; |
|
} |
|
} |
|
}
|
|
|