Пример #1
0
        private async void Conectarse(ParkForm parkForm)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                await geolocatorService.GetLocation();

                Longitude = geolocatorService.Longitude;
                Latitud   = geolocatorService.Latitud;

                AdminArea       = geolocatorService.AdminArea;
                Thoroughfare    = geolocatorService.Thoroughfare;
                Locality        = geolocatorService.Locality;
                CountryCode     = geolocatorService.CountryCode;
                CountryName     = geolocatorService.CountryName;
                PostalCode      = geolocatorService.PostalCode;
                SubLocality     = geolocatorService.SubLocality;
                SubThoroughfare = geolocatorService.SubThoroughfare;
                SubAdminArea    = geolocatorService.SubAdminArea;

                Response response = null;
                if (parkForm != null)
                {
                    if (Longitude != 0 && Latitud != 0)
                    {
                        parkForm.Longitud = Longitude;
                        parkForm.Latitud  = Latitud;

                        if (string.IsNullOrEmpty(Direccion))
                        {
                            var cadena          = "https://maps.googleapis.com/maps/api/geocode/";
                            var UrlServerMethod = "json?latlng=" + Latitud + "," + Longitude;
                            var request         = await apiService.GetGoogleService <ResponseGoogle>(cadena, UrlServerMethod);

                            if (request != null)
                            {
                                if (request.status.Equals("OK"))
                                {
                                    if (request.results.Count() > 0)
                                    {
                                        string[] caracteres = request.results.FirstOrDefault().formatted_address.Split(',');
                                        Thoroughfare = caracteres[0];
                                    }
                                }
                            }
                            Direccion = Thoroughfare;
                        }

                        var currentUser = dataService.First <User>(false);
                        if (currentUser != null && currentUser.UserId > 0)
                        {
                            parkForm.UserTypeId = currentUser.UserTypeId;
                            parkForm.UserId     = currentUser.UserId;
                            parkForm.Direccion  = Direccion;
                        }
                        else
                        {
                            isBusy    = false;
                            IsEnabled = !isBusy;
                            await dialogService.ShowMessage("Mensaje", "Usuario no identifiacado, revise su configuración");

                            return;
                        }

                        var isReachable = await CrossConnectivity.Current.IsRemoteReachable("google.com");

                        if (isReachable)
                        {
                            var respuesta = await apiService.Post <ParkForm, Response>(Configuration.SERVER, "/api", "/Parking/RegisterParking", currentUser.TokenType, currentUser.AccessToken, parkForm);

                            if (respuesta != null)
                            {
                                if (respuesta.IsSuccess)
                                {
                                    var result = (Response)respuesta.Resullt;
                                    IsBusy    = false;
                                    IsEnabled = !IsBusy;

                                    if (result.IsSuccess)
                                    {
                                        await dialogService.ShowMessage("Confirmación", result.Message);

                                        await navigationService.Navigate("MainPage");

                                        ClearFormParqueadero();
                                    }
                                    else
                                    {
                                        await dialogService.ShowMessage("Mensaje", result.Message);

                                        return;
                                    }
                                }
                                else
                                {
                                    IsBusy    = false;
                                    IsEnabled = !IsBusy;
                                    await dialogService.ShowMessage("Mensaje", "Servicio no encontrado");

                                    return;
                                }
                            }
                        }
                        else
                        {
                            IsBusy    = false;
                            IsEnabled = !IsBusy;
                            await dialogService.ShowMessage("Mensaje", "Es necesario tener conexión a internet para poder registrarse");

                            return;
                        }
                    }
                    else
                    {
                        IsBusy      = false;
                        IsEnabled   = !IsBusy;
                        ImageSource = "icon.png";
                        await dialogService.ShowMessage("Mensaje", response.Message);

                        return;
                    }
                }
                else
                {
                    IsBusy      = false;
                    IsEnabled   = !IsBusy;
                    ImageSource = "icon.png";
                    await dialogService.ShowMessage("Mensaje", "No se pudo crear el parqueadero verifique la información agregada");

                    return;
                }
            }
            else
            {
                ImageSource = "icon.png";
                await dialogService.ShowMessage("Confimación", "Es necesario tener acceso a Internet, active el Wifi o su paquete de datos por favor.");

                return;
            }
        }
Пример #2
0
        private async void Save()
        {
            if (string.IsNullOrEmpty(Nombre))
            {
                await dialogService.ShowMessage("Mensaje", "Debe ingresar el nombre del parqueadero.");

                return;
            }
            //if (string.IsNullOrEmpty(Direccion))
            //{
            //    await dialogService.ShowMessage("Mensaje", "Debe ingresar la dirección del parqueadero.");
            //    return;
            //}
            if (string.IsNullOrEmpty(Telefono_Fijo))
            {
                await dialogService.ShowMessage("Mensaje", "Debe ingresar el teléfono fijo del parqueadero.");

                return;
            }
            if (!string.IsNullOrEmpty(Telefono_Movil))
            {
                var digito = Telefono_Movil.Substring(0, 1);
                if (Convert.ToInt32(digito) != 9)
                {
                    await dialogService.ShowMessage("Mensaje", "Debe empezar el primero dígito del número móvil con el número 9");

                    return;
                }
            }

            if (string.IsNullOrEmpty(Capacidad))
            {
                await dialogService.ShowMessage("Mensaje", "Debe ingresar la cantidad de espacios del parqueadero.");

                return;
            }
            if (Id_Tipo_Parking == 0)
            {
                await dialogService.ShowMessage("Mensaje", "Seleccione un tipo de parqueadero");

                return;
            }

            #region Foto no se usa todavia
            byte[] array = null;
            if (ImageSource != null)
            {
                Stream stream = null;
                if (file != null)
                {
                    stream = file.GetStream() ?? null;
                    if (stream != null)
                    {
                        array = Utilities.ReadFully(stream);
                    }
                }
            }

            #endregion

            var parkForm = new ParkForm
            {
                Nombre          = Nombre,
                Direccion       = Direccion,
                Telefono_Fijo   = Telefono_Fijo,
                Telefono_Movil  = Telefono_Movil,
                Capacidad       = int.Parse(Capacidad),
                Id_Tipo_Parking = Id_Tipo_Parking ?? 0,
            };

            if (CrossConnectivity.Current.IsConnected)
            {
                var response = settingsService.IsPermited();

                if (!response)
                {
                    var respuesta = await dialogService.ShowMessageYesAndNot("Mensaje", "¿Desea activar el Gps para poder registrar el establecimiento de parqueo?");

                    if (!respuesta)
                    {
                        return;
                    }
                    else
                    {
                        IsBusy    = true;
                        IsEnabled = !IsBusy;
                        var resp = settingsService.IsConnected();
                        if (!resp)
                        {
                            IsBusy      = false;
                            IsEnabled   = !IsBusy;
                            ImageSource = "icon.png";
                        }
                        else
                        {
                            var result = await dialogService.ShowMessageYesAndNot("Confimación", "Estas seguro de enviar la Alerta");

                            if (result)
                            {
                                Conectarse(parkForm);
                            }
                            else
                            {
                                IsBusy      = false;
                                IsEnabled   = !IsBusy;
                                ImageSource = "icon.png";
                                return;
                            }
                        }
                    }
                }
                else
                {
                    var result = await dialogService.ShowMessageYesAndNot("Confimación", "¿Estás seguro de agregar este establecimiento de parqueo?");

                    if (result)
                    {
                        IsBusy    = true;
                        IsEnabled = !IsBusy;
                        Conectarse(parkForm);
                    }
                    else
                    {
                        IsBusy      = false;
                        IsEnabled   = !IsBusy;
                        ImageSource = "icon.png";
                        return;
                    }
                }
            }
            else
            {
                IsBusy      = false;
                IsEnabled   = !IsBusy;
                ImageSource = "icon.png";
                await dialogService.ShowMessage("Confimación", "Es necesario tener acceso a Internet, active el Wifi o su paquete de Datos por favor.");

                return;
            }
        }