Example #1
0
        public static async Task <List <RecepiesPartial> > GetAllRecepiesPartialById(int id, int pageNuber, int pageSize)
        {
            await TokenValidator.Check();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl +
                                                           $"Recipes/AllRecepiesPartialByUserId/{id}?pageNumber={pageNuber}&pageSize={pageSize}");

            return(JsonConvert.DeserializeObject <List <RecepiesPartial> >(response));
        }
Example #2
0
        public static async Task <List <FindRecepie> > FindRecepies(string title)
        {
            await TokenValidator.Check();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl +
                                                           $"Recipes/FindRecipe?recipeName={title}");

            return(JsonConvert.DeserializeObject <List <FindRecepie> >(response));
        }
Example #3
0
        public static async Task <ICollection <Recepies> > GetRecepieDetail(int id)
        {
            await TokenValidator.Check();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl +
                                                           $"Recipes/RecepieDetail/{id}");

            return(JsonConvert.DeserializeObject <ICollection <Recepies> >(response));
        }
Example #4
0
        public static async Task <bool> DeleteRecepie(int id)
        {
            await TokenValidator.Check();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));

            var response = await httpClient.DeleteAsync(AppSettings.ApiUrl +
                                                        $"Recipes/DeleteRecepie/{id}");

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
Example #5
0
        public static async Task <bool> EditRecepie(int id, Recepies recepies)
        {
            await TokenValidator.Check();

            var httpClient = new HttpClient();

            var json    = JsonConvert.SerializeObject(recepies);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));


            var response = await httpClient.PutAsync(AppSettings.ApiUrl +
                                                     $"Recipes/EditRecepie/{id}", content);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }