public async Task <CurrentPlaylistItem> AddAsync([NotNull] VideoItem videoItem) { if (videoItem == null) { throw new ArgumentNullException(nameof(videoItem)); } videoItem = await _videoRepository.GetAttachedOfFoundedAsync(videoItem, _context).ConfigureAwait(false); var maxOrder = await _context.CurrentPlaylist.AsNoTracking() .Select(s => s.Order) .DefaultIfEmpty(0) .MaxAsync() .ConfigureAwait(false); var playlistItem = new CurrentPlaylistItem(videoItem, maxOrder + 1); await _context.CurrentPlaylist.AddAsync(playlistItem).ConfigureAwait(false); _context.SaveChanges(); return(playlistItem); }
public void SeedData() { _context.Database.Migrate(); if (_env.IsProduction()) { return; } _context.Video.RemoveRange(_context.Video); _context.SaveChanges(); _context.Video.AddRange(SeedVideoItems); _context.SaveChanges(); _context.History.AddRange(SeedHistories); _context.SaveChanges(); _context.History.AddRange(GetFakeHistories(1000)); _context.SaveChanges(); for (var j = 0; j < 10; j++) { for (var i = 0; i < SeedVideoItems.Length; i++) { var vi = SeedVideoItems[i]; _context.CurrentPlaylist.Add( new CurrentPlaylistItem(vi, SeedVideoItems.Length - i + SeedVideoItems.Length * j)); } } _context.SaveChanges(); _context.Player.Video = SeedVideoItems[2]; _context.SaveChanges(); }