public void Get_First_Tv_Series() { var context = new TvContext(); var result = context.TvSeries.First(); Assert.That(result, Is.Not.Null); }
public async Task <Either <BaseError, Unit> > Handle( AddSeasonToCollection request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Parameters> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, parameters => ApplyAddSeasonRequest(dbContext, parameters))); }
public async Task <Either <BaseError, ProgramScheduleItemViewModel> > Handle( AddProgramScheduleItem request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, ProgramSchedule> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, ps => PersistItem(dbContext, request, ps))); }
public async Task <Either <BaseError, Unit> > Handle( MoveLocalLibraryPath request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Parameters> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, parameters => MovePath(dbContext, parameters))); }
public async Task <Option <Collection> > GetCollectionWithCollectionItemsUntracked(int id) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); return(await dbContext.Collections .Include(c => c.CollectionItems) .OrderBy(c => c.Id) .SingleOrDefaultAsync(c => c.Id == id) .Map(Optional)); }
public async Task <Either <BaseError, UpdateProgramScheduleResult> > Handle( UpdateProgramSchedule request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, ProgramSchedule> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, ps => ApplyUpdateRequest(dbContext, ps, request))); }
public async Task <LibraryPath> Add(LibraryPath libraryPath) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); await dbContext.LibraryPaths.AddAsync(libraryPath); await dbContext.SaveChangesAsync(); return(libraryPath); }
public async Task <List <Library> > GetAll() { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); return(await dbContext.Libraries .AsNoTracking() .Include(l => l.MediaSource) .Include(l => l.Paths) .ToListAsync()); }
public Task <List <LibraryPath> > GetLocalPaths(int libraryId) { using TvContext context = _dbContextFactory.CreateDbContext(); return(context.LocalLibraries .Include(l => l.Paths) .OrderBy(l => l.Id) .SingleOrDefaultAsync(l => l.Id == libraryId) .Map(Optional) .Match(l => l.Paths, () => new List <LibraryPath>())); }
public async Task <Either <BaseError, ChannelViewModel> > Handle( UpdateChannel request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Channel> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, c => ApplyUpdateRequest(dbContext, c, request))); }
public async Task <Either <BaseError, Unit> > Handle( RemoveItemsFromCollection request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Collection> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, c => ApplyRemoveItemsRequest(dbContext, request, c))); }
public async Task <Either <BaseError, CreatePlayoutResponse> > Handle( CreatePlayout request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Playout> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, playout => PersistPlayout(dbContext, playout))); }
public async Task <Either <BaseError, LocalLibraryViewModel> > Handle( CreateLocalLibrary request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, LocalLibrary> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, localLibrary => PersistLocalLibrary(dbContext, localLibrary))); }
public async Task <List <MovieMetadata> > GetMoviesForCards(List <int> ids) { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.MovieMetadata .AsNoTracking() .Filter(mm => ids.Contains(mm.MovieId)) .Include(mm => mm.Artwork) .OrderBy(mm => mm.SortTitle) .ToListAsync()); }
private async Task <CreatePlayoutResponse> PersistPlayout(TvContext dbContext, Playout playout) { await dbContext.Playouts.AddAsync(playout); await dbContext.SaveChangesAsync(); await _channel.WriteAsync(new BuildPlayout(playout.Id, PlayoutBuildMode.Reset)); return(new CreatePlayoutResponse(playout.Id)); }
public async Task <List <ShowMetadata> > GetShowsForCards(List <int> ids) { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.ShowMetadata .AsNoTracking() .Filter(sm => ids.Contains(sm.ShowId)) .Include(sm => sm.Artwork) .OrderBy(sm => sm.SortTitle) .ToListAsync()); }
public ActionResult Edit(Tvset item) { using (var db = new TvContext()) { var comp = db.Companies.FirstOrDefault(x => x.Name == item.Company.Name); var tech = db.Technologies.FirstOrDefault(x => x.Id == item.TechnologyId); if (Request.Files.Count != 0) { item.ImageLink = GenerateImageLink(Request.Files[0]); } if (comp == null && !string.IsNullOrWhiteSpace(item.Company.Name)) { comp = new Company { Name = item.Company.Name }; db.Companies.Add(comp); db.SaveChanges(); } item.Company = comp; item.Technology = tech; var old = db.Tvsets.FirstOrDefault(x => x.Id == item.Id); if (ModelState.IsValid && old != null) { old.Name = item.Name; old.Resolution = item.Resolution; old.Size = item.Size; old.Technology = item.Technology; old.Year = item.Year; old.Company = item.Company; old.Details = item.Details; //удаление старой картинки if (!string.Equals(old.ImageLink, item.ImageLink) && item.ImageLink != null) { if (old.ImageLink != null) { var path = "~/img/" + Path.GetFileName(old.ImageLink); System.IO.File.Delete(HostingEnvironment.MapPath(path)); } old.ImageLink = item.ImageLink; } db.SaveChanges(); return(RedirectToAction("View", new { id = item.Id })); } SelectList technologies = new SelectList(db.Technologies.ToList(), "Id", "Name"); ViewBag.Technologies = technologies; return(View()); } }
public async Task <List <Episode> > GetSeasonItems(int seasonId) { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.Episodes .AsNoTracking() .Include(e => e.EpisodeMetadata) .Include(e => e.MediaVersions) .Include(e => e.Season) .Filter(e => e.SeasonId == seasonId) .ToListAsync()); }
public async Task <List <int> > PlayoutIdsUsingSmartCollection(int smartCollectionId) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); return(await dbContext.Connection.QueryAsync <int>( @"SELECT DISTINCT p.PlayoutId FROM PlayoutProgramScheduleAnchor p WHERE p.SmartCollectionId = @SmartCollectionId", new { SmartCollectionId = smartCollectionId }) .Map(result => result.ToList())); }
public Task <Option <PlexMediaSource> > GetPlex(int id) { using TvContext context = _dbContextFactory.CreateDbContext(); return(context.PlexMediaSources .Include(p => p.Connections) .Include(p => p.Libraries) .Include(p => p.PathReplacements) .OrderBy(s => s.Id) // https://github.com/dotnet/efcore/issues/22579 .SingleOrDefaultAsync(p => p.Id == id) .Map(Optional)); }
public async Task <Option <Library> > Get(int libraryId) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); return(await dbContext.Libraries .Include(l => l.Paths) .ThenInclude(p => p.LibraryFolders) .OrderBy(l => l.Id) .SingleOrDefaultAsync(l => l.Id == libraryId) .Map(Optional)); }
private async Task <ChannelViewModel> ApplyUpdateRequest(TvContext dbContext, Channel c, UpdateChannel update) { c.Name = update.Name; c.Number = update.Number; c.Group = update.Group; c.Categories = update.Categories; c.FFmpegProfileId = update.FFmpegProfileId; c.PreferredAudioLanguageCode = update.PreferredAudioLanguageCode; c.PreferredSubtitleLanguageCode = update.PreferredSubtitleLanguageCode; c.SubtitleMode = update.SubtitleMode; c.Artwork ??= new List <Artwork>(); if (!string.IsNullOrWhiteSpace(update.Logo)) { Option <Artwork> maybeLogo = Optional(c.Artwork).Flatten().FirstOrDefault(a => a.ArtworkKind == ArtworkKind.Logo); maybeLogo.Match( artwork => { artwork.Path = update.Logo; artwork.DateUpdated = DateTime.UtcNow; }, () => { var artwork = new Artwork { Path = update.Logo, DateAdded = DateTime.UtcNow, DateUpdated = DateTime.UtcNow, ArtworkKind = ArtworkKind.Logo }; c.Artwork.Add(artwork); }); } c.StreamingMode = update.StreamingMode; c.WatermarkId = update.WatermarkId; c.FallbackFillerId = update.FallbackFillerId; await dbContext.SaveChangesAsync(); if (c.SubtitleMode != ChannelSubtitleMode.None) { Option <Playout> maybePlayout = await dbContext.Playouts .SelectOneAsync(p => p.ChannelId, p => p.ChannelId == c.Id); foreach (Playout playout in maybePlayout) { await _ffmpegWorkerChannel.WriteAsync(new ExtractEmbeddedSubtitles(playout.Id)); } } return(ProjectToViewModel(c)); }
private async Task BuildPlayouts(CancellationToken cancellationToken) { using IServiceScope scope = _serviceScopeFactory.CreateScope(); TvContext dbContext = scope.ServiceProvider.GetRequiredService <TvContext>(); List <int> playoutIds = await dbContext.Playouts.Map(p => p.Id).ToListAsync(cancellationToken); foreach (int playoutId in playoutIds) { await _channel.WriteAsync(new BuildPlayout(playoutId), cancellationToken); } }
public async Task <Either <BaseError, Unit> > Handle( ExtractEmbeddedSubtitles request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, string> validation = await FFmpegPathMustExist(dbContext); return(await validation.Match( ffmpegPath => ExtractAll(dbContext, request, ffmpegPath, cancellationToken), error => Task.FromResult <Either <BaseError, Unit> >(error.Join()))); }
public async Task DeleteLocalPath(int libraryPathId) { await using TvContext context = await _dbContextFactory.CreateDbContextAsync(); LibraryPath libraryPath = await context.LibraryPaths.FindAsync(libraryPathId); if (libraryPath != null) { context.LibraryPaths.Remove(libraryPath); await context.SaveChangesAsync(); } }
private async Task <Either <BaseError, Unit> > DoAdd(Parameters parameters) { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); return(await TraktApiClient.GetUserList(parameters.User, parameters.List) .BindT(list => SaveList(dbContext, list)) .BindT(list => SaveListItems(dbContext, list)) .BindT(list => MatchListItems(dbContext, list)) .MapT(_ => Unit.Default)); // match list items (and update in search index) }
private void UpdateRoomsList() { using (TvContext context = new TvContext()) { Room[] rooms = context.Rooms.ToArray(); listView1.Items.Clear(); foreach (Room room in rooms) { listView1.Items.Add(room.RoomId.ToString()); } } }
public ActionResult View(int id) { using (var db = new TvContext()) { var item = db.Tvsets.Include(c => c.Company).Include(t => t.Technology).FirstOrDefault(x => x.Id == id); if (item != null) { return(View(item)); } return(RedirectToAction("Index")); } }
public async Task <List <MediaSource> > GetAll() { await using TvContext context = _dbContextFactory.CreateDbContext(); List <MediaSource> all = await context.MediaSources.ToListAsync(); foreach (PlexMediaSource plex in all.OfType <PlexMediaSource>()) { await context.Entry(plex).Collection(p => p.Connections).LoadAsync(); } return(all); }
public async Task <Option <Episode> > GetEpisode(int episodeId) { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.Episodes .AsNoTracking() .Include(e => e.Season) .Include(e => e.EpisodeMetadata) .ThenInclude(em => em.Artwork) .OrderBy(s => s.Id) .SingleOrDefaultAsync(s => s.Id == episodeId) .Map(Optional)); }
public async Task <List <Season> > GetAllSeasons() { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); return(await dbContext.Seasons .AsNoTracking() .Include(s => s.SeasonMetadata) .ThenInclude(sm => sm.Artwork) .Include(s => s.Show) .ThenInclude(s => s.ShowMetadata) .ThenInclude(sm => sm.Artwork) .ToListAsync()); }