Exemplo n.º 1
0
        public ActionResult Geofence(int id)
        {
            DeviceDataService deviceDataService = new DeviceDataService();
            var device = deviceDataService.Get(id);

            return(View(device));
        }
        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 }));
            }
        }
Exemplo n.º 3
0
        public void CheckGeofence(float latitude, float longitude, int devideId)
        {
            DeviceDataService deviceDataService = new DeviceDataService();

            var device = deviceDataService.Get(devideId);

            if (latitude > device.Geofence.North || latitude < device.Geofence.South || longitude > device.Geofence.East || longitude < device.Geofence.West)
            {
                SendEmail(device.Title);
            }
            return;
        }
Exemplo n.º 4
0
        public ActionResult Index(int id)
        {
            DeviceDataService deviceDataService = new DeviceDataService();
            var device = deviceDataService.Get(id);
            LocationDataService locationDataService = new LocationDataService();
            var locations = locationDataService.GetAllByDevice(device.Id);

            if (locations.Count == 0)
            {
                return(View("NoLocationsAvailable"));
            }
            else
            {
                return(View(locations));
            }
        }