public async Task <IActionResult> Edit(long id, [Bind("OffenderGeoFenceId,OffenderId,GeoFenceName,Address,GeoFenceTypeId,NorthEastLatitude,NorthEastLongitude,SouthWestLatitude,SouthWestLongitude")] OffenderGeoFence offenderGeoFence)
        {
            if (id != offenderGeoFence.OffenderGeoFenceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(offenderGeoFence);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OffenderGeoFenceExists(offenderGeoFence.OffenderGeoFenceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new { id = offenderGeoFence.OffenderId }));
            }
            ViewData["OffenderId"] = new SelectList(_context.Offenders, "OffenderId", "OffenderName", offenderGeoFence.OffenderId);
            return(View(offenderGeoFence));
        }
        public void TestOffenderExit()
        {
            // retreive the second offender
            Offender offender = this.dbContext.Offenders.Find(2L);

            Assert.IsNotNull(offender);

            // retreive the offender's geofence
            OffenderGeoFence geoFence = this.dbContext.OffenderGeoFences.FirstOrDefault(x => x.OffenderId == offender.OffenderId);

            Assert.IsNotNull(geoFence);

            // set the last location to inside their geofence
            this.dbContext.OffenderLocations.Add(new OffenderLocation()
            {
                OffenderId   = offender.OffenderId,
                Latitude     = (geoFence.NorthEastLatitude + geoFence.SouthWestLatitude) / 2,
                Longitude    = (geoFence.NorthEastLongitude + geoFence.SouthWestLongitude) / 2,
                LocationTime = DateTimeOffset.Now.AddMinutes(-1)
            });
            this.dbContext.SaveChanges();

            // the location outside the fence
            decimal        latitude     = geoFence.SouthWestLatitude + .0123M;
            decimal        longitude    = (geoFence.NorthEastLongitude + geoFence.SouthWestLongitude) / 2;
            DateTimeOffset locationTime = DateTimeOffset.Now;

            // add the location to the offender
            OffenderNewLocationWorkflow workflow = new OffenderNewLocationWorkflow(this.dbContext, offender.OffenderId);

            workflow.AddNewLocation(latitude, longitude, locationTime);

            // ensure the location was saved to the database
            OffenderLocation insideLocation = this.dbContext.OffenderLocations.Where(x => x.OffenderId == offender.OffenderId).OrderByDescending(x => x.LocationTime).Take(1).FirstOrDefault();

            Assert.IsNotNull(insideLocation, "Expected Offender to have a last location");
            Assert.AreEqual(latitude, insideLocation.Latitude, "Expected the last locations Latidude to equal {0}", latitude);
            Assert.AreEqual(longitude, insideLocation.Longitude, "Expected the last locations Longitude to equal {0}", longitude);
            Assert.AreEqual(locationTime, insideLocation.LocationTime, "Expected the last locations LocationTime to equal {0}", locationTime);

            // validate the event
            OffenderEvent entryEvent = this.dbContext.OffenderEvents.FirstOrDefault(x => x.OffenderLocationId == insideLocation.OffenderLocationId);

            Assert.IsNotNull(entryEvent, "No Offender Event was created for the Location.");
            Assert.AreEqual(geoFence.OffenderGeoFenceId, entryEvent.OffenderGeoFenceId, "Offender Event does not match the expected GeoFence");
            Assert.AreEqual(offender.OffenderId, entryEvent.OffenderId, "The Offender Event does not match the expected Offender");
            Assert.AreEqual(EventTypeIdentifiers.Exit, entryEvent.EventTypeId, "The Event Type was expected to be an Exit event");
        }
Beispiel #3
0
        public void InsideTests()
        {
            OffenderGeoFence fence = new OffenderGeoFence()
            {
                NorthEastLatitude  = 35.843014M,
                NorthEastLongitude = -83.340230M,
                SouthWestLatitude  = 35.575827M,
                SouthWestLongitude = -83.815701M
            };

            Assert.IsTrue(fence.IsInside(35.702380M, -83.541691M));
            Assert.IsTrue(fence.IsInside(fence.NorthEastLatitude, fence.NorthEastLongitude));
            Assert.IsTrue(fence.IsInside(fence.SouthWestLatitude, fence.SouthWestLongitude));

            Assert.IsFalse(fence.IsInside(36.496245M, -83.556681M));
            Assert.IsFalse(fence.IsInside(34.613328M, -83.511595M));
            Assert.IsFalse(fence.IsInside(35.719336M, -86.137600M));
            Assert.IsFalse(fence.IsInside(35.724679M, -80.630775M));
        }
        public async Task <IActionResult> Create([Bind("OffenderGeoFenceId,OffenderId,GeoFenceName,Address,GeoFenceTypeId,NorthEastLatitude,NorthEastLongitude,SouthWestLatitude,SouthWestLongitude")] OffenderGeoFence offenderGeoFence)
        {
            if (ModelState.IsValid)
            {
                _context.Add(offenderGeoFence);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { id = offenderGeoFence.OffenderId }));
            }

            var offender = _context.Offenders.FirstOrDefault(x => x.OffenderId == offenderGeoFence.OffenderId);

            if (offender == null)
            {
                return(NotFound());
            }
            ViewData["Offender"]       = offender;
            ViewData["GeoFenceTypeId"] = this._context.GeoFenceTypes.ToList().Select(x => new SelectListItem()
            {
                Text = x.GeoFenceTypeName, Value = x.GeoFenceTypeId.ToString()
            }).ToList();

            return(View(offenderGeoFence));
        }