Exemplo n.º 1
0
        public void UpdateUser()
        {
            System.Console.WriteLine("---Update user---");

            System.Console.Write("Id:");
            int id = int.Parse(System.Console.ReadLine());

            GetUserRequest requestGet = new GetUserRequest
            {
                UserId = id
            };

            GetUserResponse responseGet = _client.GetUser(requestGet);

            if (responseGet == null)
            {
                System.Console.WriteLine("Error: response is null");
                return;
            }

            if (!responseGet.Success)
            {
                System.Console.WriteLine($"Error: {responseGet.Message}");
                return;
            }

            UpdateUserRequest requestUpdate = new UpdateUserRequest
            {
                Id          = responseGet.Id,
                IS          = responseGet.IS,
                FirstName   = responseGet.FirstName,
                LastName    = responseGet.LastName,
                DateOfBirth = responseGet.DateOfBirth,
                Salary      = responseGet.Salary
            };

            System.Console.WriteLine("Success: User found");
            System.Console.WriteLine($"IS:{requestUpdate.IS}");
            System.Console.WriteLine("Press [ESC] to skip");
            if (System.Console.ReadKey(true).Key != System.ConsoleKey.Escape)
            {
                System.Console.Write("New IS:");
                requestUpdate.IS = System.Console.ReadLine();
            }

            System.Console.WriteLine($"First Name:{requestUpdate.FirstName}");
            System.Console.WriteLine("Press [ESC] to skip");
            if (System.Console.ReadKey(true).Key != System.ConsoleKey.Escape)
            {
                System.Console.Write("New First Name:");
                requestUpdate.FirstName = System.Console.ReadLine();
            }

            System.Console.WriteLine($"Last Name:{requestUpdate.LastName}");
            System.Console.WriteLine("Press [ESC] to skip");
            if (System.Console.ReadKey(true).Key != System.ConsoleKey.Escape)
            {
                System.Console.Write("New Last Name:");
                requestUpdate.LastName = System.Console.ReadLine();
            }

            System.Console.WriteLine($"Date of Birth:{requestUpdate.DateOfBirth.Value.ToString("MM/dd/yyyy")}");
            System.Console.WriteLine("Press [ESC] to skip");
            if (System.Console.ReadKey(true).Key != System.ConsoleKey.Escape)
            {
                System.Console.Write("New Date of Birth:");
                requestUpdate.DateOfBirth = DateTime.Parse(System.Console.ReadLine());
            }

            System.Console.WriteLine($"Salary:{requestUpdate.Salary}");
            System.Console.WriteLine("Press [ESC] to skip");
            if (System.Console.ReadKey(true).Key != System.ConsoleKey.Escape)
            {
                System.Console.Write("New Salary:");
                requestUpdate.Salary = double.Parse(System.Console.ReadLine());
            }

            UpdateUserResponse responseUpdate = _client.UpdateUser(requestUpdate);

            if (responseUpdate == null)
            {
                System.Console.WriteLine("Error: response is null");
            }
            else
            if (!responseUpdate.Success)
            {
                System.Console.WriteLine($"Error: {responseUpdate.Message}");
            }
            else
            {
                System.Console.WriteLine($"Success: User updated");
            }

            System.Console.WriteLine("------------------");
        }