Example #1
0
        public async Task <IActionResult> Create([Bind("ID,Timestamp,Latitute,Longitute,Severity,Sickness")] SicknessReportModel sicknessReportModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sicknessReportModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sicknessReportModel));
        }
Example #2
0
        //severity: 0-1
        public async Task <IActionResult> SubmitReport(double latitude, double longitude, float severity, SicknessType sicknessType)
        {
            //TODO: remove this in prod
            latitude  += Fudge();
            longitude += Fudge();

            //Verify data
            latitude  = Math.Clamp(latitude, -180d, 180d);
            longitude = Math.Clamp(longitude, -180d, 180d); //what is actual lon range?
            severity  = Math.Clamp(severity, 0f, 1f);
            if (!Enum.IsDefined(typeof(SicknessType), sicknessType))
            {
                sicknessType = SicknessType.UNKNOWN_SICKNESS;
            }

            TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
            long     epochTimestamp = (long)t.TotalSeconds;

            var report = new SicknessReportModel()
            {
                Timestamp = epochTimestamp,
                Latitude  = latitude,
                Longitude = longitude,
                Severity  = severity,
                Sickness  = sicknessType,
            };

            //Store report
            if (ModelState.IsValid)
            {
                _context.Add(report);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index)); TODO: redirect?
                return(Json(new { Success = false, Message = "Sickness reported. Thanks!" }));
                //return Content("saved report to db");
            }

            return(Json(new { Success = false, Message = "Uh oh, sickness report failed!" }));
        }