Esempio n. 1
0
            private async Task <int> OnExecute(IConsole console)
            {
                var defaultForegroundColor = console.ForegroundColor;

                using (var client = EsquioClient.Create(
                           uri: Uri ?? Constants.UriDefaultValue,
                           apikey: ApiKey))
                {
                    var response = await client.AddProductAsync(Name, Description);

                    if (response.IsSuccessStatusCode)
                    {
                        console.ForegroundColor = Constants.SuccessColor;
                        console.WriteLine($"The product {Name} was added succesfully.");
                        console.ForegroundColor = defaultForegroundColor;

                        return(0);
                    }
                    else
                    {
                        console.ForegroundColor = Constants.ErrorColor;
                        console.WriteLine(await response.GetErrorDetailAsync());
                        console.ForegroundColor = defaultForegroundColor;

                        return(1);
                    }
                }
            }
Esempio n. 2
0
            private async Task <int> OnExecute(IConsole console)
            {
                var defaultForegroundColor = console.ForegroundColor;

                using (var client = EsquioClient.Create(
                           uri: Uri ?? Constants.UriDefaultValue,
                           apikey: ApiKey))
                {
                    var response = await client.ListProductsAsync();

                    if (response.IsSuccessStatusCode)
                    {
                        console.ForegroundColor = Constants.SuccessColor;
                        console.WriteLine(await response.GetContentDetailAsync());
                        console.ForegroundColor = defaultForegroundColor;

                        return(0);
                    }
                    else
                    {
                        console.ForegroundColor = Constants.ErrorColor;
                        console.WriteLine(await response.GetErrorDetailAsync());
                        console.ForegroundColor = defaultForegroundColor;

                        return(1);
                    }
                }
            }
Esempio n. 3
0
            private async Task <int> OnExecute(IConsole console)
            {
                var defaultForegroundColor = console.ForegroundColor;

                using (var client = EsquioClient.Create(
                           uri: Uri ?? Constants.UriDefaultValue,
                           apikey: ApiKey))
                {
                    var response = await client.SetParameterValue(ToggleId, ParameterName, ParameterValue);

                    if (response.IsSuccessStatusCode)
                    {
                        console.ForegroundColor = Constants.SuccessColor;
                        console.WriteLine($"The parameter {ParameterName} with value {ParameterValue} was added or updated succesfully.");
                        console.ForegroundColor = defaultForegroundColor;

                        return(0);
                    }
                    else
                    {
                        console.ForegroundColor = Constants.ErrorColor;
                        console.WriteLine(await response.GetErrorDetailAsync());
                        console.ForegroundColor = defaultForegroundColor;

                        return(1);
                    }
                }
            }
Esempio n. 4
0
            private async Task <int> OnExecute(IConsole console)
            {
                if (!NoPrompt)
                {
                    var proceed = Prompt.GetYesNo(
                        prompt: Constants.NoPromptMessage,
                        defaultAnswer: true,
                        promptColor: Constants.PromptColor,
                        promptBgColor: Constants.PromptBgColor);

                    if (!proceed)
                    {
                        return(0);
                    }
                }

                var defaultForegroundColor = console.ForegroundColor;

                using (var client = EsquioClient.Create(
                           uri: Uri ?? Constants.UriDefaultValue,
                           apikey: ApiKey))
                {
                    var response = await client.RemoveProductAsync(Id);

                    if (response.IsSuccessStatusCode)
                    {
                        console.ForegroundColor = Constants.SuccessColor;
                        console.WriteLine($"The product with identifier {Id} was removed succesfully.");
                        console.ForegroundColor = defaultForegroundColor;

                        return(0);
                    }
                    else
                    {
                        console.ForegroundColor = Constants.ErrorColor;
                        console.WriteLine(await response.GetErrorDetailAsync());
                        console.ForegroundColor = defaultForegroundColor;

                        return(1);
                    }
                }
            }