static async Task ShowOneAccount() { WorkerApi api = new WorkerApi(); Console.WriteLine(); Console.WriteLine("Pokazywanie zawartości konta konta:"); Console.WriteLine("Podaj Id konta:"); int id = int.Parse(Console.ReadLine()); (bool isSucces, string content) = await api.GetAccountData(id, _tokenSource.Token); if (isSucces) { Account account = JsonConvert.DeserializeObject <Account>(content); Console.WriteLine(); Console.WriteLine(string.Format( "ID danego konta to: {0}\nImię właściciela konta to: {1}\nNazwisko właściciela konta to: {2}\nPESEL właściciela konta to: {3}", account.Id, account.FirstName, account.LastName, account.Pesel )); Console.WriteLine("Numery kart:"); foreach (var card in account.Cards) { Console.WriteLine(card.NumberOfCard); } } else { Console.WriteLine(content); } }
static async Task UpdateAccountData() { WorkerApi api = new WorkerApi(); Console.WriteLine(); Console.WriteLine("Edycja konta. Podaj ID konta"); int id = int.Parse(Console.ReadLine()); (bool isSucces, string content) = await api.GetAccountData(id, _tokenSource.Token); if (isSucces) { Account account = JsonConvert.DeserializeObject <Account>(content); Console.WriteLine("-------------------"); bool isEnd = false; do { Console.WriteLine(); Console.WriteLine("Podaj co chcesz zmodyfikować (imię, nazwisko, PESEL, karty, zakończ):"); string command = Console.ReadLine(); switch (command) { case "karty": { Console.WriteLine("Dodać lub usunąć?"); string cardCommand = Console.ReadLine(); if (cardCommand.ToLower() == "dodać") { (isSucces, content) = await api.AddCardToAccount(account.Id, _tokenSource.Token); if (!isSucces) { Console.WriteLine(content); } } else if (cardCommand.ToLower() == "usunąć") { Console.WriteLine("Podaj nr karty do usunięcia:"); string cardNumber = Console.ReadLine(); (isSucces, content) = await api.RemoveCardToAccount( account.Id, cardNumber, _tokenSource.Token); if (!isSucces) { Console.WriteLine(content); } } else { Console.WriteLine("Błędna komenda"); } } break; case "imię": { Console.WriteLine("Podaj imię:"); account.FirstName = Console.ReadLine(); break; } case "nazwisko": { Console.WriteLine("Podaj nazwisko:"); account.LastName = Console.ReadLine(); break; } case "PESEL": { Console.WriteLine("Podaj PESEL:"); account.Pesel = Console.ReadLine(); break; } case "zakończ": { (isSucces, content) = await api.UpdateAccountData(account, _tokenSource.Token); if (!isSucces) { Console.WriteLine(content); } Console.WriteLine("Poprawiono konto o numerze ID " + id); isEnd = true; break; } default: break; } } while (!isEnd); } else { Console.WriteLine(content); } }