Exemple #1
0
        async void MoveToCurrentLocation()
        {
            await geolocatorService.GetLocation();

            if (geolocatorService.Latitude != 0 && geolocatorService.Longitude != 0)
            {
                var position = new Position(geolocatorService.Latitude, geolocatorService.Longitude);
                MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(.3)));
            }
            Task.Run(async() => backgroundThread());
        }
Exemple #2
0
        async void MoveToCurrentLocation()
        {
            await geolocatorService.GetLocation();

            if (geolocatorService.Latitude != 0 && geolocatorService.Longitude != 0)
            {
                var position = new Position(geolocatorService.Latitude, geolocatorService.Longitude);
                MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(.3)));
            }

            await ShowPoins();
        }
        async void MoveMapToCurrentPosition()
        {
            await geolocatorService.GetLocation();

            if (geolocatorService.Latitude != 0 ||
                geolocatorService.Longitude != 0)
            {
                var position = new Position(
                    geolocatorService.Latitude,
                    geolocatorService.Longitude);
                MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(
                                       position,
                                       Distance.FromKilometers(.5)));
            }
            await LoadPins();
        }
Exemple #4
0
        private async void saveCurrentPosittion()
        {
            await geolocatorService.GetLocation();

            if (geolocatorService.Latitude == 0 ||
                geolocatorService.Longitude == 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "No se a logrado ubicar tu localizacion",
                    "Aceptar");

                return;
            }

            var user = MainViewModel.GetInstance().User;

            user.Latitude  = (decimal)geolocatorService.Latitude;
            user.Longitude = (decimal)geolocatorService.Longitude;

            var apiSecurity = Application.Current.Resources["APISecurity"].ToString();
            var response    = await this.apiService.Put(
                apiSecurity,
                "/api",
                "/Users",
                MainViewModel.GetInstance().Token.TokenType,
                MainViewModel.GetInstance().Token.AccessToken,
                user);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    response.Message,
                    "Aceptar");

                return;
            }

            //TODO: Notificacion push
            //await Application.Current.MainPage.DisplayAlert(
            //    "Confirmación",
            //    "Tu pocicion esta siendo rastreada por nuestros sistemas",
            //    "Aceptar");
        }
Exemple #5
0
        private async void OnInitAsync()
        {
            MyMap.Tapped    += MyMap_Tapped;
            MyMap.PinTapped += MyMap_PinTapped;

            await _geolocatorService.GetLocation();

            if (_geolocatorService.Lat > 0 || _geolocatorService.Lon > 0)
            {
                var position = new Position(_geolocatorService.Lat, _geolocatorService.Lon);
                MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromKilometers(.5)));
            }
            else
            {
                await DisplayAlert("Geolocation", "Geolocation service not available!", "Ok");
            }

            GetParkings();
        }
		async void Save()
		{
			if (ProjectId == 0)
			{
				await dialogService.ShowMessage("Error", "You must select a project.");
				return;
			}

			if (ActivityId == 0)
			{
				await dialogService.ShowMessage("Error", "You must select an activity.");
				return;
			}

			ConvertHours();

			if (To <= From)
			{
				await dialogService.ShowMessage("Error", "The hour 'To' must be greather hour 'From'.");
				return;
			}

			IsEnabled = false;
			IsRunning = true;

			var checkConnetion = await apiService.CheckConnection();
			if (!checkConnetion.IsSuccess)
			{
				IsRunning = false;
				IsEnabled = true;
				await dialogService.ShowMessage("Error", checkConnetion.Message);
				return;
			}

			var urlAPI = Application.Current.Resources["URLAPI"].ToString();
			var mainViewModel = MainViewModel.GetInstance();
			var employee = mainViewModel.Employee;

			await geolocatorService.GetLocation();

			var newTimeRequest = new NewTimeRequest
			{
				ActivityId = ActivityId,
				DateReported = DateReported,
				EmployeeId = employee.EmployeeId,
				From = From,
				Latitude = geolocatorService.Latitude,
				Longitude = geolocatorService.Longitude,
				IsRepeated = IsRepeated,
				IsRepeatFriday = IsRepeatFriday,
				IsRepeatMonday = IsRepeatMonday,
				IsRepeatSaturday = IsRepeatSaturday,
				IsRepeatSunday = IsRepeatSunday,
				IsRepeatThursday = IsRepeatThursday,
				IsRepeatTuesday = IsRepeatTuesday,
				IsRepeatWednesday = IsRepeatWednesday,
				ProjectId = ProjectId,
				Remarks = Remarks,
				To = To,
				Until = Until,
			};

			var response = await apiService.Post(
				urlAPI,
				"/api",
				"/Times",
				employee.TokenType,
				employee.AccessToken,
				newTimeRequest);

			IsEnabled = true;
			IsRunning = false;

			if (!response.IsSuccess)
			{
				await dialogService.ShowMessage("Error", response.Message);
				return;
			}

			await navigationService.Back();
		}
Exemple #7
0
        private async void NewCustomer()
        {
            if (string.IsNullOrEmpty(UserName))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Email.");

                return;
            }
            if (!Utilities.IsValidEmail(UserName))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Email valido.");

                return;
            }
            if (string.IsNullOrEmpty(FirstName))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Nombres.");

                return;
            }
            if (string.IsNullOrEmpty(LastName))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Apellidos.");

                return;
            }
            if (string.IsNullOrEmpty(Phone))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Telefono.");

                return;
            }
            if (string.IsNullOrEmpty(Address))
            {
                await dialogService.ShowMessage("Error", "Debe ingresar una Direccion.");

                return;
            }
            if (DepartmentId == 0)
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Departamento.");

                return;
            }
            if (CityId == 0)
            {
                await dialogService.ShowMessage("Error", "Debe ingresar un Telefono.");

                return;
            }

            IsRunning = true;
            await geolocatorService.GetLocation();

            var customer = new Customer
            {
                Address      = Address,
                CityId       = CityId,
                DepartmentId = DepartmentId,
                FirstName    = FirstName,
                LastName     = LastName,
                IsUpdated    = true,
                Phone        = Phone,
                Latitude     = geolocatorService.Latitude,
                Longitude    = geolocatorService.Longitude,
                UserName     = UserName,
            };

            var response = await apiService.NewCustomer(customer);

            if (response.IsSucces && file != null)
            {
                var newCustomer = (Customer)response.Result;
                var response2   = await apiService.SetPhoto(newCustomer.CustomerId, file.GetStream());

                var filenName = string.Format("{0}.jpg", newCustomer.CustomerId);
                var folder    = "~/Content/Customers";
                var fullPath  = string.Format("{0}/{1}", folder, filenName);
                customer.Photo = fullPath;
            }

            IsRunning = false;
            if (!response.IsSucces)
            {
                await dialogService.ShowMessage("Error", response.Message);

                return;
            }

            await dialogService.ShowMessage("Confirmación.", response.Message);

            await navigationService.Back();
        }
Exemple #8
0
        async void Save()
        {
            if (ProjectId == 0)
            {
                await dialogService.ShowMessage("Error", "You must select a project.");

                return;
            }

            if (ActivityId == 0)
            {
                await dialogService.ShowMessage("Error", "You must select an activity.");

                return;
            }

            ConvertHours();

            if (To <= From)
            {
                await dialogService.ShowMessage("Error", "The hour 'To' must be greather hour 'From'.");

                return;
            }

            IsEnabled = false;
            IsRunning = true;

            var checkConnetion = await apiService.CheckConnection();

            if (!checkConnetion.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", checkConnetion.Message);

                return;
            }

            await geolocatorService.GetLocation();

            var activitySelected = Activities.ElementAt(ActivityIndex);
            var projectSelected  = Projects.ElementAt(ProjectIndex);

            var time = new Time
            {
                Activity       = activitySelected,
                ActivityId     = activitySelected.ActivityId,
                DateRegistered = DateTime.Today,
                DateReported   = DateReported,
                EmployeeId     = employee.EmployeeId,
                From           = From,
                Project        = projectSelected,
                ProjectId      = projectSelected.ProjectId,
                Remarks        = Remarks,
                TimeId         = editTime.TimeId,
                To             = To,
            };

            var response = await apiService.Put(
                urlAPI,
                "/api",
                "/Times",
                employee.TokenType,
                employee.AccessToken,
                time);

            IsEnabled = true;
            IsRunning = false;

            if (!response.IsSuccess)
            {
                await dialogService.ShowMessage("Error", response.Message);

                return;
            }

            await navigationService.Back();
        }
        private async void BuscarParqueaderoPorUsuario(User user)
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                await geolocatorService.GetLocation();

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

                if (Longitude != 0 && Latitud != 0)
                {
                    searchParkForm.Longitude = Longitude.ToString();
                    searchParkForm.Latitud   = Latitud.ToString();

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

                    if (isReachable)
                    {
                        var sear = new SearchParkForm {
                            Latitud   = searchParkForm.Latitud,
                            Longitude = searchParkForm.Longitude
                        };

                        var respuesta = await apiService.Post <SearchParkForm, ResponseT <List <Parqueadero> > >(Configuration.SERVER,
                                                                                                                 "/api", "/Parking/SearchParking", user.TokenType, user.AccessToken, sear);

                        if (respuesta != null)
                        {
                            if (respuesta.IsSuccess)
                            {
                                var result    = (ResponseT <List <Parqueadero> >)respuesta.Resullt;
                                var parqExits = dataService.Get <Parqueadero>(false).ToList();

                                if (result.IsSuccess)
                                {
                                    var listParqueaderos = (List <Parqueadero>)result.Result;
                                    ReloadParqueaderos(listParqueaderos);
                                    await navigationService.Navigate("MapUbicateParkingPage");

                                    IsBusy    = false;
                                    IsEnabled = !IsBusy;
                                }
                                else
                                {
                                    IsBusy    = false;
                                    IsEnabled = !IsBusy;
                                    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;
                    await dialogService.ShowMessage("Mensaje", "Es necesario tener encendido el Gps para poder ubicar los sitios más cercanos");

                    return;
                }
            }
            else
            {
                IsBusy    = false;
                IsEnabled = !IsBusy;
                await dialogService.ShowMessage("Mensaje", "Active su Wifi o su paquete de datos.");

                return;
            }
        }
        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;
            }
        }
        private async void Start()
        {
            if (string.IsNullOrEmpty(MyRoute))
            {
                await dialogService.ShowMessage("Error", "Seleccione una ruta.");

                return;
            }
            //IsEnabledStart = false;
            //var checkConnection = await apiService.CheckConnection();
            //if (!checkConnection.IsSuccess)
            //{
            //    IsRunning = false;
            //    await dialogService.ShowMessage("Error", checkConnection.Message);
            //    return;

            //}

            var mainViewModel = MainViewModel.GetInstance();
            var urlAPI        = Application.Current.Resources["URLAPI"].ToString();
            var response      = await apiService.GetByField <Location>(
                urlAPI,
                "/locations.json",
                "placa",
                mainViewModel.Driver.Placa,
                mainViewModel.Driver.Token);

            if (response.IsSuccess)
            {
                //IsEnabledStart = true;
                //await dialogService.ShowMessage("Error", "Problemas registrando el viaje.");
                var responseDelete = await apiService.Delete(
                    urlAPI,
                    "/locations",
                    mainViewModel.Driver.Token,
                    response.Extra);
            }

            await geolocatorService.GetLocation();

            var newLocation = new Location
            {
                Placa    = mainViewModel.Driver.Placa,
                Vehiculo = mainViewModel.Driver.Vehiculo,
                Ruta     = MyRoute,
                Latitud  = geolocatorService.Latitude,
                Longitud = geolocatorService.Longitude,
                Hora     = DateTime.Now.ToLocalTime().ToString()
            };

            var responsePost = await apiService.Post <Location>(
                urlAPI,
                "/locations",
                ".json",
                newLocation,
                mainViewModel.Driver.Token);

            if (!responsePost.IsSuccess)
            {
                IsEnabledStart = true;
                await dialogService.ShowMessage("Error", "No se ha podido iniciar el viaje");

                return;
            }
            var postResponse = (PostResponse)responsePost.Result;

            key            = postResponse.Name;
            IsEnabledEnd   = true;
            IsEnabledStart = false;

            Task.Factory.StartNew(() => backgroundThread(), TaskCreationOptions.LongRunning);
            //Task.Run(async () => backgroundThread());
        }