예제 #1
0
        public async Task <IEnumerable <Client> > GetAllClients()
        {
            IEnumerable <Client> clientsData;
            string key = "CachingKey";

            HttpResponseMessage Response = await _httpClient.GetAsync("v2/5808862710000087232b75ac");

            if (Response.IsSuccessStatusCode)
            {
                using Stream responseStream = await Response.Content.ReadAsStreamAsync();

                ListOfClients listOfClients = await JsonSerializer.DeserializeAsync <ListOfClients>(responseStream);

                clientsData = listOfClients.Clients;

                // Store data in the cache.
                _cache.Set <IEnumerable <Client> >(key, clientsData);

                return(clientsData);
            }
            else
            {
                // In case webservice is not reachable/does not respond return persisted
                // data from cache (from last succesfull call to Webservice).
                if (!_cache.TryGetValue(key, out clientsData))
                {
                    throw new Exception("Clients data cannot be retrieved from backend webservice and there is no clients data available in the cache.");
                }
                else
                {
                    // Return persistent data from last succesfull call to Webservice.
                    return(clientsData);
                }
            }
        }
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            //otwarcie nowego okna klienta
            var clientWindow = new clientWindow();

            if (clientWindow.ShowDialog() == true)
            {
                //szczytanie i przypisanie wartosci do nowej instancji klasy typu client
                Client client = new Client()
                {
                    name    = clientWindow.nameTextbox.Text,
                    surname = clientWindow.surnameTextbox.Text
                };
                ListOfClients.Add(client);
            }
        }