Exemple #1
0
        async public Task <List <ProductModel> > GetProducts(Guid restaurantId)
        {
            if (DeviceService.CheckConnectivity())
            {
                using (var client = new HttpClient())
                {
                    var response = await client.GetAsync(new
                                                         Uri($"https://cedesistemas-app-api.azurewebsites.net/api/Restaurantes/{restaurantId}/Productos"));

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

                        StorageService.Set($"Products_{restaurantId}", content);
                        return(JsonConvert.DeserializeObject <List <ProductModel> >(content));
                    }
                }
            }
            else
            {
                string content = await StorageService.Get($"Products_{restaurantId}");

                return(JsonConvert.DeserializeObject <List <ProductModel> >(content));
            }
            return(null);
        }
Exemple #2
0
        async public Task <bool> SaveStudent(StudentModel student)
        {
            if (DeviceService.CheckConnectivity())
            {
                using (var client = new HttpClient())
                {
                    string json = JsonConvert.SerializeObject(student);
                    var    body = new StringContent(json, Encoding.UTF8, "application/json");

                    var response = await client.PostAsync(
                        "https://cedesistemas-app-api.azurewebsites.net/api/Estudiantes", body);

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