示例#1
0
        private void GetHotels()
        {
            Action <Dictionary <string, HotelModel> > onValueEvent = null;

            onValueEvent = (Dictionary <string, HotelModel> hotels) =>
            {
                try
                {
                    System.Diagnostics.Debug.WriteLine("---> EVENT GetDataFromFirebase ");

                    Action onSetValueSuccess = () =>
                    {
                    };

                    Action <string> onSetValueError = (string errorDesc) =>
                    {
                    };

                    if (hotels != null)
                    {
                        if (hotels.Count == 0)
                        {
                            hotellist.IsVisible = false;
                            info.IsVisible      = true;
                        }

                        if (hotels.Count != 0 && hotels.Count != hotelsList.Count)
                        {
                            hotellist.IsVisible = true;
                            info.IsVisible      = false;
                            hotelsList.Clear();

                            foreach (KeyValuePair <string, HotelModel> item in hotels)
                            {
                                if (hotelsList.All(d => d.Key != item.Value.Key))
                                {
                                    if (item.Value.Status)
                                    {
                                        hotelsList.Add(item.Value);
                                    }
                                }
                            }
                            if (hotelsList.Count > 0)
                            {
                                hotellist.ItemsSource  = hotelsList;
                                hotellist.IsRefreshing = false;
                                info.IsVisible         = false;
                            }
                            else
                            {
                                hotellist.IsRefreshing = false;
                                info.IsVisible         = true;
                            }
                        }
                    }
                    else
                    {
                        hotellist.IsVisible = false;
                        info.IsVisible      = true;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("---> error GetDataFromFirebase " + ex.Message);
                }
            };

            _firebaseDatabase.GetHotels("hotels", onValueEvent);
        }