using System; using System.Collections.Generic; using System.Threading.Tasks; using PetaPoco; using PetaPoco.Business; namespace Sony.Filtr.Core.Buzz { [Serializable] [TableName("tblBuzzArtist")] [PrimaryKey("Id", autoIncrement = true)] public class BuzzArtist { [Column("Id")] public int Id { get; set; } [Column("ArtistName")] public string ArtistName { get; set; } [Column("ArtistId")] public string SpotifyArtistId { get; set; } [Column("ProfileName")] public string ArtistSpotifyUserName { get; set; } [Column("Followers")] public int Followers { get; set; } } [Serializable] [TableName("tblSpotifyArtistFollowerLog")] public class SpotifyArtistFollowerLogItem { [Column("ArtistId")] public string ArtistId { get; set; } [Column("Date")] public DateTime Date { get; set; } [Column("Followers")] public int Followers { get; set; } [Column("Timestamp")] [ResultColumn] public DateTime Timestamp { get; set; } } public class BuzzArtistManager { public List GetBuzzArtists() { return PetaPocoRepository.Instance.Fetch(); } public BuzzArtist GetBuzzArtistBySpotifyId(string spotifyArtistId) { return PetaPocoRepository.Instance.SingleOrDefaultWithSql("WHERE ArtistID=@0", spotifyArtistId); } public BuzzArtist AddBuzzArtist(BuzzArtist buzzArtist) { var id = PetaPocoRepository.Instance.Insert(buzzArtist); buzzArtist.Id = id; return buzzArtist; } public BuzzArtist GetBuzzArtist(int id) { return PetaPocoRepository.Instance.SingleOrDefault(id); } public void DeleteBuzzArtist(BuzzArtist existing) { PetaPocoRepository.Instance.Delete(existing.Id); } public void UpdateBuzzArtist(BuzzArtist buzzArtist) { PetaPocoRepository.Instance.Update(buzzArtist); } public async Task> GetSpotifyArtistFollowerLogAsync(string artistId, DateTime startDate, DateTime endDate) { var sql = PetaPoco.Sql.Builder.Append("WHERE ArtistId = @0 AND Date >= @1 AND Date <= @2", artistId, startDate, endDate); return PetaPocoRepository.Instance.Fetch(sql); } public async Task> GetSpotifyArtistFollowerLogAsync(DateTime date) { var sql = PetaPoco.Sql.Builder.Append("WHERE Date = @0", date); return PetaPocoRepository.Instance.Fetch(sql); } } }