예제 #1
0
        public Recipe CreateRecipe(Recipe recipe)
        {
            if (_token.GetToken() == null)
            {
                return(null);
            }

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.GetToken());

            HttpResponseMessage response = _client.PostAsJsonAsync("/api/recipes", recipe).Result;
            string stringData            = response.Content.ReadAsStringAsync().Result;
            Recipe data = JsonConvert.DeserializeObject <Recipe>(stringData);

            if (response.IsSuccessStatusCode)
            {
                return(data);
            }
            return(null);
        }
예제 #2
0
        public UserService(AuthTokenService token)
        {
            _token = token;
            _client.BaseAddress = new Uri("http://localhost:5001");
            MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");

            _client.DefaultRequestHeaders.Accept.Add(contentType);

            if (_token.GetToken() != null)
            {
                _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.GetToken());
            }
        }
예제 #3
0
        public IEnumerable <Favorite> GetFavorites()
        {
            if (_token.GetToken() == null)
            {
                return(null);
            }

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.GetToken());
            HttpResponseMessage response = _client.GetAsync("/api/users/favorites").Result;
            string stringData            = response.Content.ReadAsStringAsync().Result;

            IEnumerable <Favorite> data = JsonConvert.DeserializeObject <IEnumerable <Favorite> >(stringData);

            return(data);
        }