Example #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);
            }
        }
Example #2
0
        // GET: StopsEdit
        public ActionResult Index(StopChangeAudits stopChangeAudit, int stopid, int submissionId, string submissionEndDate)
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorizedAdmin)
                {
                    return(RedirectToAction("Unauthorized", "Home"));
                }
            }

            UserProfile_Conf uid = dbr.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == User.Identity.Name.ToString());

            ViewBag.UserProfileID = uid.UserProfileID;
            ViewBag.admin         = user.authorizedAdmin;
            // web.config debug setting
            ViewBag.debug       = HttpContext.IsDebuggingEnabled;
            ViewBag.personCount = 0;
            ViewBag.test        = ConfigurationManager.AppSettings["test"];

            //If Id is being passed from submission portal
            if (stopid != 0)
            {
                stopChangeAudit.StopID = stopid;
            }
            else
            {
                ViewBag.submissionID = 0;
            }
            ViewBag.submissionID      = submissionId;
            ViewBag.submissionEndDate = submissionEndDate;

            if (stopChangeAudit.StopID != 0)
            {
                ViewBag.stopID = stopChangeAudit.StopID;

                DateTime fromDate = Convert.ToDateTime("2018-07-01");
                Stop     stop     = dbr.Stop
                                    .Where(x => x.ID == stopChangeAudit.StopID && x.Time >= fromDate)
                                    .Select(x => x).FirstOrDefault();

                if (stop == null)
                {
                    ModelState.AddModelError(string.Empty, "The Stop ID you entered does not exists or is older than July 1st 2018!");
                }
                else
                {
                    ViewBag.postSubRedact = stopChangeAudit.postSubRedact;
                    //if (stopChangeAudit.postSubRedact)
                    //{
                    //    stop.Status = "postSubRedact";
                    //    state = dbr.Entry(stop).State;
                    //    dbr.SaveChanges();
                    //}

                    if (stop.Status == "success" && !stopChangeAudit.postSubRedact)
                    {
                        ModelState.AddModelError(string.Empty, "The Stop ID #" + stopChangeAudit.StopID + " has been successfully submitted to DOJ. It cannot be modified.");
                    }
                    else
                    {
                        JObject o          = JObject.Parse(stop.JsonStop);
                        JArray  personList = (JArray)o["ListPerson_Stopped"];
                        ViewBag.personCount = personList.Count;
                    }
                }
            }

            return(View(stopChangeAudit));
        }