Ejemplo n.º 1
0
        public async Task <List <User> > GetInactivesFirstAccess()
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _userAuth.GetToken());

                using (var response = await httpClient.GetAsync($"{baseUrl}/GetInactivesFirstAccess"))
                {
                    string apiResponse = await response.Content.ReadAsStringAsync();

                    var result = JsonConvert.DeserializeObject <List <User> >(apiResponse);
                    return(result);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <ProductResult> Create(Product Product)
        {
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _userAuth.GetToken());

                StringContent conteudo = new StringContent(JsonConvert.SerializeObject(Product), Encoding.UTF8, "application/json");

                using (var response = await httpClient.PostAsync($"{baseUrl}/Create", conteudo))
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        return(new ProductResult()
                        {
                            Success = false,
                            Message = "Acesso Negado. ",
                            Notifications = new List <Notification>()
                            {
                                new Notification()
                                {
                                    Property = string.Empty, Message = "Usuário sem permissão. "
                                }
                            }
                        });
                    }

                    string apiResponse = await response.Content.ReadAsStringAsync();

                    var result = JsonConvert.DeserializeObject <ProductResult>(apiResponse);
                    return(result);
                }
            }
        }