コード例 #1
0
        //[ValidateAntiForgeryToken]
        public IHttpActionResult PutStop(JObject jsonStop, int stopId, string changeAuditReason, int submissionEdit, bool postSubRedact)
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorizedAdmin)
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
            }

            ExtractJNode eJson;

            eJson = new ExtractJNode("JsonStop", jsonStop);
            string jsonStopStr = eJson.traverseNode();
            Stop   stop        = db.Stop.Find(stopId);

            if (postSubRedact && stop.Status == "success")
            {
                stop.Status = "postSubRedact";
            }
            string originalJson = stop.JsonStop;

            stop.JsonStop = Regex.Replace(jsonStopStr, @"\p{Cs}", ""); // remove emojis

            CommonRoutines cr = new CommonRoutines();

            try
            {
                StopChangeAudits newAuditRec = new StopChangeAudits();
                newAuditRec.StopID       = stopId;
                newAuditRec.OrigJsonStop = originalJson;
                newAuditRec.Time         = DateTime.Now;
                newAuditRec.NTUserName   = User.Identity.Name.ToString();
                newAuditRec.ModJsonStop  = jsonStopStr;
                newAuditRec.Reason       = changeAuditReason;
                if (ModelState.IsValid)
                {
                    dbe.StopChangeAudits.Add(newAuditRec);
                    dbe.SaveChanges();
                }

                if (stop.SubmissionsID != null)
                {
                    JObject submissionO    = JObject.Parse(stop.JsonSubmissions);
                    JObject lastSubmission = (JObject)submissionO["SubmissionInfo"].Last();
                    lastSubmission["edited"] = true;
                    stop.JsonSubmissions     = JsonConvert.SerializeObject(submissionO);
                }
                string dojJson = "";

                if (stop.Status == "fail")
                {
                    dojJson = cr.dojTransform(stop, "U");
                }

                if (stop.Status == "fatal" || stop.Status == null || postSubRedact || stop.Status == "postSubRedact")
                {
                    dojJson = cr.dojTransform(stop, "I");
                }

                stop.JsonDojStop     = dojJson;
                db.Entry(stop).State = EntityState.Modified;
                db.SaveChanges();
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }
コード例 #2
0
        //[ValidateAntiForgeryToken]
        //[AllowAnonymous]
        public async Task <ActionResult> Create([Bind(Include = "ID,JsonStop,JsonInstrumentation,latitude,longitude,beat,UserProfileID,PersonCount")] Stop stop)
        {
            UserProfile_Conf uid = db.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == User.Identity.Name.ToString());

            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                HomeController.UserAuth user = new HomeController.UserAuth();
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
            }

            //stop.ID = Guid.NewGuid();
            stop.Time          = DateTime.Now;
            stop.Latitude      = string.IsNullOrEmpty(stop.Latitude) ? null : stop.Latitude;
            stop.Longitude     = string.IsNullOrEmpty(stop.Longitude) ? null : stop.Longitude;
            stop.Beat          = string.IsNullOrEmpty(stop.Beat) ? null : stop.Beat;
            stop.UserProfileID = uid.UserProfileID;

            stop.JsonStop = Regex.Replace(stop.JsonStop, @"\p{Cs}", ""); // remove emojies

            //Todo: extract info from JsonStop
            CommonRoutines cr = new CommonRoutines();

            string[] OfficerIDDateTime = cr.getOfficerIDDateTime(stop.JsonStop);

            // Dedupe. Check for existing before proceeding. Using only OfficerID & Date/Time per DOJ service validation. Comparing the
            // whole json payload would potentially introduce duplicate OfficerID & Date/Time combinations.
            string officerID = OfficerIDDateTime[0];
            string stopDate  = OfficerIDDateTime[1];
            string StopTime  = OfficerIDDateTime[2];
            bool   exist     = db_lookup.StopOfficerIDDateTime_JSON_vw
                               .Any(x => x.officerID == officerID && x.stopDate == stopDate && x.StopTime == StopTime);

            if (!exist)
            {
                db.Stop.Add(stop);

                try
                {
                    db.SaveChanges();
                    //return RedirectToAction("Index");
                    string dojJson = cr.dojTransform(stop, "I");
                    stop.JsonDojStop     = dojJson;
                    db.Entry(stop).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
                }
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict));
            }
        }