using PetaPoco; using System; using System.Collections.Generic; using System.Text; using PetaPoco.Business; using System.Threading.Tasks; namespace Sony.Filtr.YouTube.Charts { public class YouTubeChartsManager { public List GetChartPlaylists() { return PetaPocoRepository.ReadOnlyInstance.Fetch("WHERE Active = 1"); } public async Task AddChartEntriesAsync(string countryCode, DateTime date, YouTubeChartType chartType, List entries) { var chart = new YouTubeChartPlaylistChart() { CountryCode = countryCode, Date = date, ChartType = chartType }; PetaPocoRepository.Instance.Insert(chart); entries.ForEach(e=> e.ChartId = chart.Id); await PetaPocoRepository.Instance.BulkInsertAsync(entries, ignoreExisting: true); return chart.Id; } public List GetCharts(DateTime today) { return PetaPocoRepository.ReadOnlyInstance.Fetch("WHERE date = @0", today); } } [TableName("tblYoutubeChart")] [PrimaryKey("Id")] public class YouTubeChartPlaylistChart { public int Id { get; set; } public string CountryCode { get; set; } public DateTime Date { get; set; } public YouTubeChartType ChartType { get; set; } [ResultColumn] public DateTime Timestamp { get; set; } } [TableName("tblYoutubeChartPlaylist")] public class YouTubeChartPlaylist { public string CountryCode { get; set; } public string PlaylistId { get; set; } public YouTubeChartType ChartType { get; set; } } [TableName("tblYoutubeChartEntry")] public class YouTubeChartEntry { public int ChartId { get; set; } public string VideoId { get; set; } public string Title { get; set; } public string ChannelId { get; set; } public string ChannelTitle { get; set; } public int Position { get; set; } } public enum YouTubeChartType { TopSongs = 1, Trending = 2, MusicVideo = 3, WeeklyTopVideos = 4, } }