Ejemplo n.º 1
0
        public async Task LoadClinincs()
        {
            Clinics.Clear();

            if (IsEmergency)
            {
                double latitude  = 0;
                double longitude = 0;

                try
                {
                    double.TryParse(servicesPageViewModel.AddressSelected.Latitude.Replace(".", phoneService.CurrentCulture.NumberFormat.CurrencyDecimalSeparator), out latitude);
                    double.TryParse(servicesPageViewModel.AddressSelected.Longitude.Replace(".", phoneService.CurrentCulture.NumberFormat.CurrencyDecimalSeparator), out longitude);
                }
                catch
                {
                    latitude  = servicesPageViewModel.CurrentLocation.Latitude;
                    longitude = servicesPageViewModel.CurrentLocation.Longitude;
                }

                CurrentLocation = new Position
                {
                    Latitude  = latitude,
                    Longitude = longitude,
                };
            }

            dialogService.ShowProgress();
            RequestClinics        request = new RequestClinics();
            ResponseNearbyClinics responseNearbyClinics = await apiService.GetClinics(request);

            dialogService.HideProgress();
            if (responseNearbyClinics.Success)
            {
                LoadNearbyClinics(responseNearbyClinics);
            }
            else
            {
                await dialogService.ShowMessage(AppResources.TitleWithoutConnection, AppResources.WithoutConnection);

                await navigationService.Back();
            }
        }
Ejemplo n.º 2
0
        private void LoadNearbyClinics(ResponseNearbyClinics responseNearbyClinics)
        {
            try
            {
                Clinics.Clear();
                IList <Clinic> nearbyClinics = new List <Clinic>();
                foreach (Clinic item in responseNearbyClinics.Clinics)
                {
                    if (CurrentLocation != null)
                    {
                        item.Distance = ViewModelHelper.Distance(CurrentLocation.Latitude, CurrentLocation.Longitude,
                                                                 double.Parse(item.Latitude.Replace(".", phoneService.CurrentCulture.NumberFormat.CurrencyDecimalSeparator)),
                                                                 double.Parse(item.Longitude.Replace(".", phoneService.CurrentCulture.NumberFormat.CurrencyDecimalSeparator)));
                    }

                    nearbyClinics.Add(item);
                }

                IList <Clinic> clinicsOrdered = new List <Clinic>();

                if (CurrentLocation != null)
                {
                    clinicsOrdered = nearbyClinics.OrderBy(x => x.Distance).ToList();
                }
                else
                {
                    clinicsOrdered = nearbyClinics.OrderBy(x => x.Name).ToList();
                }

                Clinics.Clear();

                foreach (var item in clinicsOrdered)
                {
                    ClinicViewModel clinicViewModel = new ClinicViewModel();
                    ViewModelHelper.SetClinicToClinicViewModel(clinicViewModel, item, phoneService.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
                    Clinics.Add(clinicViewModel);
                }
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 3
0
 public void Clear()
 {
     Clinics?.Clear();
 }