using Microsoft.EntityFrameworkCore; using Modules.Library.Database.Database; using Modules.Library.Database.Database.Models.Anime; using System.Linq.Expressions; namespace Modules.Library.Database.Repositories; public class AnimeSeasonRepository(AnimeTitleRepository titleRepository, LibraryDbContext context) { private readonly LibraryDbContext _context = context; internal async Task AddAsync(Guid animeTitleId, AnimeSeason animeSeason) { var dbTitle = await titleRepository.GetFirstWhere(q => q.Id == animeTitleId); dbTitle.Items.Add(animeSeason); await _context.SaveChangesAsync(); return animeSeason.Id; } private IQueryable QueryFullIncludes() => _context.AnimeSeasons .Include(q => q.Title) .Include(q => q.CommonProperties).ThenInclude(q => q.Names) .Include(q => q.CommonProperties).ThenInclude(q => q.Descriptions) .Include(q => q.CommonProperties).ThenInclude(q => q.RelatedContent) .Include(q => q.CommonProperties).ThenInclude(q => q.Genres) .Include(q => q.CommonProperties).ThenInclude(q => q.Preview) .Include(q => q.Episodes).ThenInclude(q => q.CommonProperties).ThenInclude(q => q.Names) .Include(q => q.Episodes).ThenInclude(q => q.CommonProperties).ThenInclude(q => q.Descriptions) .Include(q => q.Episodes).ThenInclude(q => q.CommonProperties).ThenInclude(q => q.RelatedContent) .Include(q => q.Episodes).ThenInclude(q => q.CommonProperties).ThenInclude(q => q.Genres) .Include(q => q.Episodes).ThenInclude(q => q.CommonProperties).ThenInclude(q => q.Preview) .AsQueryable(); //internal async Task> GetAllAsync() => await QueryFullIncludes().ToListAsync(); internal async Task GetFirstWhere(Expression> predicate) => await QueryFullIncludes().FirstAsync(predicate); internal async Task UpdateAsync(Guid titleId, AnimeSeason animeSeason) { var dbSeason = await GetFirstWhere(q => q.Title.Id == titleId && q.Id == animeSeason.Id); CommonPropertiesHelper.SyncCommonProperties(dbSeason.CommonProperties, animeSeason.CommonProperties); dbSeason.ExpirationTime = animeSeason.ExpirationTime; dbSeason.Completed = animeSeason.Completed; dbSeason.Deleted = animeSeason.Deleted; await _context.SaveChangesAsync(); } internal async Task DeleteAsync(Guid titleId, Guid animeSeasonId) { var dbSeason = await GetFirstWhere(q => q.Title.Id == titleId && q.Id == animeSeasonId); _context.AnimeSeasons.Remove(dbSeason); await _context.SaveChangesAsync(); } //protected override async Task SoftDeleteAsync(AnimeTitle entity) //{ // entity.Deleted = true; // return await UpdateAsync(entity); //} /* public async Task AddAsync(Domain.Entities.MediaContent.Items.Anime.AnimeTitle entity, IUser user) => await AddAsync(ToDbConverter.Title(entity)); public Task AnyWhere(Expression> predicate) { var p = predicate. } public Task DeleteAsync(Domain.Entities.MediaContent.Items.Anime.AnimeTitle entity, IUser user) { throw new NotImplementedException(); } public Task GetByIdAsync(string id) { throw new NotImplementedException(); } public Task GetByIdOrDefaultAsync(string id) { throw new NotImplementedException(); } public Task GetFirstOrDefaultWhere(Expression> predicate) { throw new NotImplementedException(); } public Task GetFirstWhere(Expression> predicate) { throw new NotImplementedException(); } public Task> GetRangeByIdsAsync(List ids) { throw new NotImplementedException(); } public Task> GetWhere(Expression> predicate) { throw new NotImplementedException(); } public Task UpdateAsync(Domain.Entities.MediaContent.Items.Anime.AnimeTitle entity, IUser user) { throw new NotImplementedException(); } Task> Application.Gateways.IRepository.GetAllAsync() { throw new NotImplementedException(); } */ }