Esempio n. 1
0
        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);
            }
        }