예제 #1
0
        private void MButtonAdd_Click(object sender, EventArgs e)
        {
            mProgressBar.Visibility = Android.Views.ViewStates.Visible;
            Location newLoc = new Location()
            {
                Name          = mLocationName.Text,
                Address       = mLocationAddress.Text,
                Description   = mLocationDescription.Text,
                CreatedUserId = mAuthorizedId.ToString(),
                AddedUserId   = mAuthorizedId.ToString()
            };

            new Thread(new ThreadStart(delegate
            {
                var isAdded = mLocationDataService.Add(newLoc);

                if (isAdded)
                {
                    LoadData();
                    UpgradeProgress();
                    this.Activity.RunOnUiThread(() => Toast.MakeText(this.Activity, "Location Added", ToastLength.Long).Show());
                    mProgressBar.Visibility = Android.Views.ViewStates.Invisible;
                }
                else
                {
                    this.Activity.RunOnUiThread(() => Toast.MakeText(this.Activity, "Failed", ToastLength.Long).Show());
                }
            })).Start();
        }
예제 #2
0
        private void AddLocationDialog_OnLocationAdd(object sender, OnAddLocationEventArgs e)
        {
            Location newLoc = new Location()
            {
                Name          = e.Name,
                Address       = e.Address,
                Description   = e.Description,
                CreatedUserId = mAuthorizedId.ToString()
            };
            var progressDialog = ProgressDialog.Show(this, "Please wait...", "Adding Location...", true);

            new Thread(new ThreadStart(delegate
            {
                var isAdded = mLocationDataService.Add(newLoc);
                RunOnUiThread(() => progressDialog.Hide());

                if (isAdded)
                {
                    RunOnUiThread(() => Toast.MakeText(this, "Location Added", ToastLength.Long).Show());
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(this, "Failed to add, please check again form's field", ToastLength.Long).Show());
                }
            })).Start();
        }
        public IHttpActionResult AddLocation(LocationModel locatioModel)
        {
            // To call this method: http://localhost:12345/Api/LocationData/AddLocation

            DeviceDataService deviceDataService = new DeviceDataService();

            var device = deviceDataService.Get(locatioModel.DeviceId);

            if (device == null)
            {
                return(Json("Toks įrenginys neegzistuoja"));
            }
            else
            {
                LocationDataService locationDataService = new LocationDataService();

                Location location = new Location
                {
                    Longitude = locatioModel.Longitude,
                    Latitude  = locatioModel.Latitude,
                    TimeStamp = locatioModel.TimeStamp,
                    DeviceId  = device.Id
                };

                locationDataService.Add(location);

                var jsonLocation = new
                {
                    latitude  = locatioModel.Latitude,
                    longitude = locatioModel.Longitude
                };

                var options = new PusherOptions
                {
                    Cluster   = "eu",
                    Encrypted = true
                };

                var _pusher = new Pusher(
                    "526323",
                    "e3eb2284cbb62f35599f",
                    "52decc2ad70da06be4d0",
                    options);


                _pusher.TriggerAsync("location_channel", "new_location", jsonLocation);

                GeofencingServices geofencingServices = new GeofencingServices();

                geofencingServices.CheckGeofence(locatioModel.Longitude, locatioModel.Latitude, locatioModel.DeviceId);

                return(Json(new { status = "success", data = location }));
            }
        }