Ejemplo n.º 1
0
        public static async Task <bool> CreateClientCommandAsync(ClientCommand clientCommand)
        {
            string        clientCommandJs = JsonConvert.SerializeObject(clientCommand);
            StringContent data            = new StringContent(clientCommandJs, Encoding.UTF8, "application/json");

            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri("https://localhost:44311/api/");
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await httpClient.PostAsync("ClientCommands", data);

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static async Task <ClientCommand> GetOneClientCommandAsync(int id)
        {
            ClientCommand cliCommand = new ClientCommand();

            using (var HttpClient = new HttpClient())
            {
                HttpResponseMessage response = await HttpClient.GetAsync("https://localhost:44311/api/ClientCommands/" + id);

                if (response.IsSuccessStatusCode)
                {
                    string data = await response.Content.ReadAsStringAsync();

                    cliCommand = JsonConvert.DeserializeObject <ClientCommand>(data);

                    Client client = await Client.GetOneClientAsync(cliCommand.ClientId);

                    cliCommand.ClientName = client.LastName + " " + client.FirstName;
                }
            }
            return(cliCommand);
        }