Пример #1
0
        public IHttpActionResult GettestCircularAlarm(int id)
        {
            checkFence cf = new checkFence();
            var location = (from l in db.Pacman_location_db
                        where (l.ID == id)
                        orderby l.ID descending
                        select l).First();
            var client = (from c in db.Pacman_carer_db
                          where c.ID == location.id_carer
                          select c).FirstOrDefault();
            cf.careDeviceId = client.device_id;

            var pncl = (from c in db.Pacman_patient_db
                        where c.ID == location.id_patient
                        select c).FirstOrDefault();
            cf.patientName = pncl.name;
            if (location != null)
            {

                //cf.patientx = 1;
                //cf.patienty = 2;
                cf.patientx = location.coordinates_x;
                cf.patienty = location.coordinates_y;
                var fence = (from f in db.Pacman_fence_db
                             where (f.id_patient == location.id_patient)
                             orderby f.ID descending
                             select f).FirstOrDefault();
                cf.fencex = Convert.ToDecimal(fence.Latitude);
                cf.fencey = Convert.ToDecimal(fence.Longitude);
                cf.radius = fence.radius;

                //cf.distanceCheck();
                //return Ok(cf.apiResult);
            }
            try
            {

                var p = (from f in db.Fences
                        where f.PatientID == location.id_patient
                        orderby f.ID descending
                        select f).FirstOrDefault();

                var points = from fencePoint in db.FencePoints
                                where fencePoint.FenceID == p.ID
                                orderby fencePoint.ID
                                select fencePoint;

                var sides = Tuplise(points.ToList());

                if (!CheckPolygonFence.CheckPointInside(sides, location))
                {

                    cf.alarm();

                }

            }
            catch (Exception ex)
            {

            }

            return Ok();
        }
Пример #2
0
        public IHttpActionResult PostPacman_location_db(Pacman_location_db location)
        {
            checkFence cf = new checkFence();
            var client = (from c in db.Pacman_carer_db
                          where c.ID == location.id_carer
                          select c).FirstOrDefault();
            cf.careDeviceId = client.device_id;

            var pncl = (from c in db.Pacman_patient_db
                        where c.ID == location.id_patient
                        select c).FirstOrDefault();
            cf.patientName = pncl.name;

            if (location != null)
            {
                location.ID = null;
            }
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Pacman_location_db.Add(location);
            db.SaveChanges();

            location = db.Pacman_location_db.Find(location.ID);

            if (location != null)
            {

                cf.patientx = location.coordinates_x;
                cf.patienty = location.coordinates_y;
                var fence = (from f in db.Pacman_fence_db
                             where (f.id_patient == location.id_patient)
                             orderby f.ID descending
                             select f).FirstOrDefault();
                if (fence != null)
                {
                    cf.fencex = Convert.ToDecimal(fence.Latitude);
                    cf.fencey = Convert.ToDecimal(fence.Longitude);
                    cf.radius = fence.radius;

                    cf.distanceCheck();
                }

                try
                {
                    var pFence  = (from f in db.Fences
                             where f.PatientID == location.id_patient
                             orderby f.ID descending
                             select f).FirstOrDefault();

                    if (pFence != null) {
                        var points = from fencePoint in db.FencePoints
                                     where fencePoint.FenceID == pFence.ID
                                     orderby fencePoint.ID
                                     select fencePoint;

                        var sides = Tuplise(points.ToList());

                        if (!CheckPolygonFence.CheckPointInside(sides, location))
                        {
                            cf.alarm();
                        }
                    }

                }
                catch (Exception ex)
                {

                }

            }

            return CreatedAtRoute("DefaultApi", new { id = location.ID }, location);
        }