示例#1
0
        static async Task PostAsync()
        {
            using (var client = createClient())
            {
                try
                {
                    Console.WriteLine("MÉTODO POST");
                    Console.WriteLine("");

                    Console.WriteLine("ADICIONAR EXPERIÊNCIA");
                    Console.WriteLine("");

                    Console.Write("Company Name: ");
                    var companyName = Console.ReadLine();

                    Experiences newExperience = new Experiences();
                    newExperience.companyname = companyName;

                    response = await client.PostAsJsonAsync("experiences", newExperience);

                    if (response.IsSuccessStatusCode)
                    {
                        Uri experienceUrl = response.Headers.Location;
                        //Console.WriteLine(experienceUrl);
                        Console.WriteLine("");
                        Console.WriteLine(companyName + " adicionada com sucesso");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("JSON offline...");
                }
            }
        }
示例#2
0
        static async Task DeleteAsync()
        {
            using (var client = createClient())
            {
                try
                {
                    Console.WriteLine("MÉTODO DELETE");
                    Console.WriteLine("");

                    Console.WriteLine("DELETAR EXPERIÊNCIA");
                    Console.WriteLine("");

                    Console.Write("Informe o ID para ser deletado: ");
                    var companyId = Console.ReadLine();

                    Console.WriteLine("Carregando...");
                    Console.WriteLine("");

                    response = await client.GetAsync("experiences/" + companyId);

                    if (response.IsSuccessStatusCode)
                    {
                        Experiences showExperiencebyId = await response.Content.ReadAsAsync <Experiences>();

                        Console.WriteLine("Nome da Compania: " + showExperiencebyId.companyname);

                        Console.Write("Tem certeza que deseja deletar " + showExperiencebyId.companyname + "(Y/N): ");
                        var checkDelete = Console.ReadLine();
                        if (checkDelete == "Y")
                        {
                            response = await client.DeleteAsync("experiences/" + companyId);

                            if (response.IsSuccessStatusCode)
                            {
                                Uri experienceUrl = response.Headers.Location;
                                Console.WriteLine("");
                                Console.WriteLine(companyId + " deletada com sucesso");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("JSON offline...");
                }
            }
        }
示例#3
0
        static async Task UpdateAsync()
        {
            using (var client = createClient())
            {
                try
                {
                    Console.WriteLine("MÉTODO UPDATE");
                    Console.WriteLine("");
                    Console.Write("Informe o ID para fazer a alteração: ");
                    var companyCheckId = Console.ReadLine();

                    Console.WriteLine("Carregando...");
                    Console.WriteLine("");


                    response = await client.GetAsync("experiences/" + companyCheckId);

                    if (response.IsSuccessStatusCode)
                    {
                        Experiences showExperiencebyId = await response.Content.ReadAsAsync <Experiences>();

                        Console.WriteLine("Nome da Compania: " + showExperiencebyId.companyname);
                    }

                    Console.Write("Informe o novo nome: ");
                    var companyUpdateName = Console.ReadLine();

                    Experiences newExperience = new Experiences();

                    newExperience.companyname = companyUpdateName;
                    response = await client.PutAsJsonAsync("experiences/" + companyCheckId, newExperience);

                    if (response.IsSuccessStatusCode)
                    {
                        Uri experienceUrl = response.Headers.Location;
                        //    //Console.WriteLine(experienceUrl);
                        Console.WriteLine("");
                        Console.WriteLine(companyUpdateName + " atualizado(a) com sucesso");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("JSON offline...");
                }
            }
        }