using System.Text.Json.Serialization;
namespace MusicKeyTranslator.Models;
internal class Music
{
[JsonPropertyName("song")]
public string? Song { get; set; }
[JsonPropertyName("key")]
public int Key { get; set; }
private readonly Dictionary<int, string> dic = new()
{
{ 0, "C" },
{ 1, "C#" },
{ 2, "D" },
{ 3, "D#" },
{ 4, "E" },
{ 5, "F" },
{ 6, "F#" },
{ 7, "G" },
{ 8, "G#" },
{ 9, "A" },
{ 10, "A#" },
{ 11, "B" },
};
public void SearchMusicThroughTone(List<Music> list, string value)
{
int position = dic.FirstOrDefault(x => x.Value == value).Key;
if (position == 1)
{
list.RemoveAll(a => a.Key != position);
foreach (var item in list)
{
Console.WriteLine(item.Song + " - " + item.Key);
}
}
}
}
using System.Text.Json;
namespace MusicKeyTranslator.Models;
internal class Service
{
public static async Task SearchMusic()
{
using (HttpClient client = new())
{
var response = await client.GetStringAsync("https://guilhermeonrails.github.io/api-csharp-songs/songs.jsonList");
var jsonList = JsonSerializer.Deserialize<List<Music>>(response)!;
Music model = new();
Console.WriteLine("Você quer pegar a tonalidade de qual música?");
string tom = Console.ReadLine()!;
model.SearchMusicThroughTone(jsonList, tom);
}
}
}