コード例 #1
0
        public void OnGet()
        {
            String crimeIncidentJSON = GetData("https://data.cincinnati-oh.gov/resource/k59e-2pvf.json");
            var    crimeIncidents    = CrimeIncidents.FromJson(crimeIncidentJSON);

            ViewData["CrimeIncidents"] = crimeIncidents;


            String smart911EnrollmentJSON = GetData("https://data.cincinnati-oh.gov/resource/rtu7-isj6.json");
            var    smart911Enrollments    = Smart911Enrollment.FromJson(smart911EnrollmentJSON);

            ViewData["Smart911Enrollments"] = smart911Enrollments;

            IDictionary <long, CrimeIncident.CrimeIncidents> incidentsMap = new Dictionary <long, CrimeIncidents>();
            List <SmartEnrollment.Smart911Enrollment>        enrollist    = new List <Smart911Enrollment>();

            foreach (CrimeIncident.CrimeIncidents crInc in crimeIncidents)
            {
                if (!incidentsMap.ContainsKey(crInc.Zip))
                {
                    incidentsMap.Add(crInc.Zip, crInc);
                }
            }

            foreach (SmartEnrollment.Smart911Enrollment enroll in smart911Enrollments)
            {
                if (incidentsMap.ContainsKey(enroll.ZipCode))
                {
                    enrollist.Add(enroll);
                }
            }
            ViewData["Enrollist"] = enrollist;
        }
コード例 #2
0
        public IActionResult Edit(Details d)
        {
            CrimeIncidents a   = db.crimeIncident.Where(a => a.objectid == d.objectid).FirstOrDefault();
            var            old = a;

            a.Agency       = db.Agency.Where(t => t.cmid == a.cmid).FirstOrDefault();
            a.blockaddress = d.blockaddress;
            a.type         = d.type;
            a.status       = d.status;

            db.crimeIncident.Remove(old);
            db.SaveChanges();
            db.crimeIncident.Add(a);
            db.SaveChanges();

            ViewBag.dbUpdate = 1;

            Details det = new Details();

            det.objectid     = a.objectid;
            det.blockaddress = a.blockaddress;
            det.cmid         = a.cmid;
            det.cmagency     = a.Agency.cmagency;
            det.date         = a.date;
            det.type         = a.type;
            det.status       = a.status;

            return(View(det));
        }
コード例 #3
0
        public static void Initialize(ApplicationDbContext dbContext)
        {
            APIHandler webHandler = new APIHandler();

            List <RootData>       jsonData        = webHandler.GetData();
            List <CrimeIncidents> crimeIncidents1 = new List <CrimeIncidents>();
            List <CMAgency>       Agency          = new List <CMAgency>();

            foreach (RootData data in jsonData)
            {
                var validIds = dbContext.crimeIncident.Select(t => t.objectid).ToList();
                if (!validIds.Contains(data.objectid))
                {
                    CrimeIncidents incident = new CrimeIncidents();
                    CMAgency       agency   = new CMAgency();
                    agency.kilonbr        = data.kilonbr;
                    agency.cmid           = data.cmid;
                    agency.cmagency       = data.cmagency;
                    incident.objectid     = data.objectid;
                    incident.cmid         = data.cmid;
                    incident.Agency       = agency;
                    incident.date         = data.date;
                    incident.blockaddress = data.blockaddress;
                    incident.score        = data.score;
                    incident.side         = data.side;
                    incident.type         = data.type;
                    incident.status       = data.status;
                    incident.favorite     = 0;
                    agency.crimeIncident  = incident;
                    crimeIncidents1.Add(incident);
                    Agency.Add(agency);
                }
            }

            foreach (CrimeIncidents incident in crimeIncidents1)
            {
                // crimeIncident.RemoveRange();
                dbContext.crimeIncident.Add(incident);
                dbContext.SaveChanges();
            }
            foreach (CMAgency agency in Agency)
            {
                // dbContext.Agency.RemoveRange();
                dbContext.Agency.Add(agency);
                dbContext.SaveChanges();
            }
            dbContext.SaveChanges();
        }
コード例 #4
0
        public IActionResult Edit(int id)
        {
            CrimeIncidents a = db.crimeIncident.Where(a => a.objectid == id).FirstOrDefault();

            a.Agency = db.Agency.Where(t => t.cmid == a.cmid).FirstOrDefault();
            Details d = new Details();

            d.objectid     = a.objectid;
            d.blockaddress = a.blockaddress;
            d.cmid         = a.cmid;
            d.cmagency     = a.Agency.cmagency;
            d.date         = a.date;
            d.type         = a.type;
            d.status       = a.status;

            return(View(d));
        }
コード例 #5
0
        public void OnPost()
        {
            using (var webClient = new WebClient())
            {
                String crimeIncidentJSON = webClient.DownloadString("https://data.cincinnati-oh.gov/resource/k59e-2pvf.json");
                crimes = CrimeIncidents.FromJson(crimeIncidentJSON);


                String smart911EnrollmentJSON = webClient.DownloadString("https://data.cincinnati-oh.gov/resource/rtu7-isj6.json");
                enrollments = Smart911Enrollment.FromJson(smart911EnrollmentJSON);

                crimesFiltered      = crimes.Where(x => x.Zip == zipSearch).ToArray();
                enrollmentsFiltered = enrollments.Where(x => x.ZipCode == zipSearch).ToArray();

                ViewData["CrimeIncidents"]      = crimesFiltered;
                ViewData["Smart911Enrollments"] = enrollmentsFiltered;
            }
            searchFinished = true;
        }
        public IList <SmartEnrollmentAPI> GetSmartEnrollmentAPI()
        {
            IList <SmartEnrollmentAPI> outputJson = new List <SmartEnrollmentAPI>();

            using (var webClient = new WebClient())
            {
                String crimeIncidentJSON = webClient.DownloadString("https://data.cincinnati-oh.gov/resource/k59e-2pvf.json");
                var    crimeIncidents    = CrimeIncidents.FromJson(crimeIncidentJSON);

                String smart911EnrollmentJSON = webClient.DownloadString("https://data.cincinnati-oh.gov/resource/rtu7-isj6.json");
                var    smart911Enrollments    = Smart911Enrollment.FromJson(smart911EnrollmentJSON);

                IDictionary <long, CrimeIncident.CrimeIncidents> incidentsMap = new Dictionary <long, CrimeIncidents>();

                foreach (CrimeIncident.CrimeIncidents crInc in crimeIncidents)
                {
                    if (!incidentsMap.ContainsKey(crInc.Zip))
                    {
                        incidentsMap.Add(crInc.Zip, crInc);
                    }
                }

                foreach (SmartEnrollment.Smart911Enrollment enroll in smart911Enrollments)
                {
                    if (incidentsMap.ContainsKey(enroll.ZipCode))
                    {
                        SmartEnrollmentAPI enrollment = new SmartEnrollmentAPI();
                        enrollment.Zipcode          = enroll.ZipCode;
                        enrollment.WebEnrollments   = enroll.WebEnrollments;
                        enrollment.AppEnrollments   = enroll.AppEnrollments;
                        enrollment.TotalEnrollments = enroll.TotalEnrollments;
                        outputJson.Add(enrollment);
                    }
                }
            }
            return(outputJson);
        }