Example #1
0
        private async void updateFactories()
        {
            try
            {
                txtInfo.Text = "şirketler yükleniyor...";
                if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None)
                {
                    txtInfo.Text = "İnternet bağlantısını kontrol ediniz.\nTekrar denemek için dokunun.";
                    txtInfo.Tap += TxtInfo_Tap;
                    return;
                }
                Global.Token = CryptoHelper.CreateToken(DeviceHelper.Id);
                var factoriesResponse = await FactoryRequests.GetFactoriesAsync();

                if (factoriesResponse.Status)
                {
                    var factories = factoriesResponse.Result as List <Factory>;
                    if (factories != null)
                    {
                        Database.UpdateFactories(factories);
                    }
                    prepare();
                }
                else
                {
                    txtInfo.Text = "Bir sorun oluştu.\nTekrar denemek için dokunun.";
                    txtInfo.Tap += TxtInfo_Tap;
                }
            }
            catch (Exception)
            {
                txtInfo.Text = "Bir sorun oluştu.\nTekrar denemek için dokunun.";
                txtInfo.Tap += TxtInfo_Tap;
            }
        }
        private async void updateFactories(int?id = null)
        {
            if (NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None)
            {
                var message = new Message();
                message.Content = "İnternet bağlantınızı kontrol ediniz.";
                message.Buttons.Add(new MessageButton("Tamam", "closeMessage()"));
                showMessage(message);
            }
            else
            {
                if (id == null)
                {
                    Global.Token = CryptoHelper.CreateToken(DeviceHelper.Id);
                    var factoriesResponse = await FactoryRequests.GetFactoriesAsync();

                    if (factoriesResponse.Status)
                    {
                        var factories = factoriesResponse.Result as List <Factory>;
                        if (factories != null)
                        {
                            Database.UpdateFactories(factories);
                        }
                        lsFactories.ItemsSource = null;
                        lsFactories.ItemsSource = Database.SavedData.Factories.OrderBy(x => x.Sort).ToList();
                        lsHistory.ItemsSource   = null;
                        lsHistory.ItemsSource   = Database.SavedData.History;
                    }
                    else if (factoriesResponse.Message != null)
                    {
                        showMessage(factoriesResponse.Message);
                    }
                }
                else
                {
                    Global.Token = CryptoHelper.CreateToken(DeviceHelper.Id);
                    var factoriesResponse = await FactoryRequests.GetFactoryDetailsAsync((int)id);

                    if (factoriesResponse.Status)
                    {
                        var factory = factoriesResponse.Result as Factory;
                        if (factory != null)
                        {
                            Database.AddFactory(factory);
                        }
                        lsFactories.ItemsSource = null;
                        lsFactories.ItemsSource = Database.SavedData.Factories.OrderBy(x => x.Sort).ToList();
                        lsHistory.ItemsSource   = null;
                        lsHistory.ItemsSource   = Database.SavedData.History;
                    }
                    else if (factoriesResponse.Message != null)
                    {
                        showMessage(factoriesResponse.Message);
                    }
                }
            }
        }