Esempio n. 1
0
        // GET: Stops
        public ActionResult Index()
        {
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                HomeController.UserAuth user = new HomeController.UserAuth();
                user          = HomeController.AuthorizeUser(User.Identity.Name.ToString());
                ViewBag.admin = user.authorizedAdmin;

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

            //UserProfile_Conf uid = db.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == User.Identity.Name.ToString());
            //ViewBag.UserProfileID = uid.UserProfileID;
            //ViewBag.test = ConfigurationManager.AppSettings["test"];
            //List<Stop> Stops = await db.Stop.Where(x => x.UserProfileID == uid.UserProfileID).OrderByDescending(x => x.Time).ToListAsync();
            //foreach(Stop st in Stops)
            //{
            //    if(st.JsonStop != null)
            //    {
            //        st.JsonStop = JValue.Parse(st.JsonStop).ToString(Formatting.Indented);
            //    }

            //}

            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;

            //return View(Stops);
            return(View());
        }
        // GET: UserProfiles/Edit/5
        public ActionResult Edit(int?id)
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserProfile userProfile = db.UserProfiles.Find(id);

            if (userProfile == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserProfileID = userProfile.ID;
            ViewBag.admin         = user.authorizedAdmin;

            if (!string.IsNullOrEmpty(userProfile.Assignment))
            {
                userProfile.Assignment = string.Format("{0} {1}", userProfile.AssignmentKey, userProfile.Assignment);
            }
            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;
            return(View(userProfile));
        }
Esempio n. 3
0
        //// GET: UserProfiles/Details/5
        //public ActionResult Details(Guid? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    UserProfile userProfile = db.UserProfiles.Find(id);
        //    if (userProfile == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(userProfile);
        //}


        // GET: UserProfiles/Create
        public ActionResult Create()
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

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

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

            // web.config debug setting
            ViewBag.debug  = HttpContext.IsDebuggingEnabled;
            ViewBag.agency = ConfigurationManager.AppSettings["agency"];
            ViewBag.ori    = ConfigurationManager.AppSettings["ori"];
            ViewBag.admin  = user.authorizedAdmin;


            if (User.Identity.IsAuthenticated && UserProfile_Conf == null)
            {
                return(View());
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Edit([Bind(Include = "ID,Agency,ORI,Years,Assignment,AssignmentOther")] UserProfile userProfile)
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
            }
            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;
            ViewBag.admin = user.authorizedAdmin;
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(userProfile.Assignment))
                {
                    userProfile.AssignmentKey = Int32.Parse(userProfile.Assignment.Substring(0, userProfile.Assignment.IndexOf(' ')));
                    userProfile.Assignment    = userProfile.Assignment.Substring(userProfile.Assignment.IndexOf(' ') + 1, userProfile.Assignment.Length - userProfile.Assignment.IndexOf(' ') - 1);
                    if (userProfile.AssignmentKey != 10)
                    {
                        userProfile.AssignmentOther = null;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(userProfile.AssignmentOther))
                        {
                            ViewBag.ErrorOtherType = "Please enter a description for assignment";
                            return(View());
                        }
                        if (userProfile.AssignmentOther.Length < 3)
                        {
                            ViewBag.ErrorOtherType = "Please enter at least 3 characters for this field.";
                            return(View());
                        }
                    }
                }

                userProfile.Agency = ConfigurationManager.AppSettings["agency"];
                userProfile.ORI    = ConfigurationManager.AppSettings["ori"];

                db.Entry(userProfile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            // web.config debug setting
            //ViewBag.debug = HttpContext.IsDebuggingEnabled;
            return(View(userProfile));
        }
Esempio n. 5
0
        // GET: StopsEdit/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(int?stopid, int pid, int pidCount, int submissionId, string submissionEndDate, bool postSubRedact)
        {
            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.stopID            = stopid;
            ViewBag.pid               = pid;
            ViewBag.personCount       = pidCount;
            ViewBag.submissionID      = submissionId;
            ViewBag.submissionEndDate = ViewBag.submissionEndDate;

            if (submissionId == 0)
            {
                ViewBag.submissionEdit = 0;
            }
            else
            {
                ViewBag.submissionEdit = 1;
            }
            ViewBag.submissionEndDate = submissionEndDate;

            ViewBag.expireCacheDays      = ConfigurationManager.AppSettings["expireCacheDays"];
            ViewBag.reverseGeoURI        = ConfigurationManager.AppSettings["reverseGeoURI"];
            ViewBag.reverseBeatURI       = ConfigurationManager.AppSettings["reverseBeatURI"];
            ViewBag.server               = System.Environment.MachineName;
            ViewBag.forceCacheUpdate     = ConfigurationManager.AppSettings["forceCacheUpdate"];
            ViewBag.allowedBackDateHours = ConfigurationManager.AppSettings["allowedBackDateHours"];
            ViewBag.useBeats             = ConfigurationManager.AppSettings["useBeats"];
            ViewBag.test = ConfigurationManager.AppSettings["test"];
            ViewBag.useAdditionalQuestions = ConfigurationManager.AppSettings["useAdditionalQuestions"];
            ViewBag.useContractCity        = ConfigurationManager.AppSettings["useContractCity"];
            ViewBag.useContractEvent       = ConfigurationManager.AppSettings["useContractEvent"];
            ViewBag.editStop      = 1;
            ViewBag.postSubRedact = postSubRedact;

            return(View());
        }
Esempio n. 6
0
        // GET: UserProfiles/Edit/5
        public ActionResult Edit(int?id)
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserProfile userProfile = db.UserProfiles.Find(id);

            if (userProfile == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserProfileID = userProfile.ID;
            ViewBag.admin         = user.authorizedAdmin;
            string useContractCity = ConfigurationManager.AppSettings["useContractCity"];

            ViewBag.useContractCity  = useContractCity;
            ViewBag.useContractEvent = ConfigurationManager.AppSettings["useContractEvent"];

            if (useContractCity == "1")
            {
                //create SelectListItem
                userProfile.citiesList = dbl.ContractCities.
                                         Select(a => new SelectListItem
                {
                    Text  = a.ContractCity.ToString().Trim(),                           // name to show in html dropdown
                    Value = a.ContractCity.ToString().Trim(),                           // value of html dropdown
                }).ToList();
            }

            if (!string.IsNullOrEmpty(userProfile.Assignment))
            {
                userProfile.Assignment = string.Format("{0} {1}", userProfile.AssignmentKey, userProfile.Assignment);
            }
            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;
            return(View(userProfile));
        }
Esempio n. 7
0
        // GET: Stops
        public ActionResult Index()
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user          = HomeController.AuthorizeUser(User.Identity.Name.ToString());
                ViewBag.admin = user.authorizedAdmin;

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
                uid = db.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == User.Identity.Name.ToString());
            }
            else
            {
                // Anonymous user without Authentication can still run this app
                uid = db.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == "AnonymousUser");
            }

            ViewBag.admin         = user.authorizedAdmin;
            ViewBag.UserProfileID = uid.UserProfileID;
            ViewBag.test          = ConfigurationManager.AppSettings["test"];
            List <Stop> Stops = db.Stop.Where(x => x.UserProfileID == uid.UserProfileID).OrderByDescending(x => x.Time).ToList();

            foreach (Stop st in Stops)
            {
                if (st.JsonStop != null)
                {
                    st.JsonStop = JValue.Parse(st.JsonStop).ToString(Formatting.Indented);
                }
            }

            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;

            //return View(Stops); some words here
            return(View());
        }
        public ActionResult Create([Bind(Include = "ID,Agency,ORI,Years,Assignment,AssignmentOther")] UserProfile userProfile)
        {
            string userName;

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

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
                if (User.Identity.IsAuthenticated)
                {
                    proceed = true;
                }
                else
                {
                    proceed = false;
                }
                userName = User.Identity.Name;
            }
            else
            {
                proceed  = true;
                userName = "******";
            }
            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;
            ViewBag.admin = user.authorizedAdmin;

            if (ModelState.IsValid && proceed)
            {
                //userProfile.ID = Guid.NewGuid();
                if (!string.IsNullOrEmpty(userProfile.Assignment))
                {
                    userProfile.AssignmentKey = Int32.Parse(userProfile.Assignment.Substring(0, userProfile.Assignment.IndexOf(' ')));
                    userProfile.Assignment    = userProfile.Assignment.Substring(userProfile.Assignment.IndexOf(' ') + 1, userProfile.Assignment.Length - userProfile.Assignment.IndexOf(' ') - 1);
                    if (userProfile.AssignmentKey != 10)
                    {
                        userProfile.AssignmentOther = null;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(userProfile.AssignmentOther))
                        {
                            ViewBag.ErrorOtherType = "Please enter a description for assignment";
                            return(View());
                        }
                        if (userProfile.AssignmentOther.Length < 3)
                        {
                            ViewBag.ErrorOtherType = "Please enter at least 3 characters for this field.";
                            return(View());
                        }
                    }
                }

                userProfile.Agency = ConfigurationManager.AppSettings["agency"];
                userProfile.ORI    = ConfigurationManager.AppSettings["ori"];


                db.UserProfiles.Add(userProfile);
                db.UserProfile_Conf.Add(
                    new UserProfile_Conf()
                {
                    NTUserName    = userName,
                    UserProfileID = userProfile.ID
                }
                    );
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            //return RedirectToAction("Index", "Home");
            //return View(userProfile);
            return(View());
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
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));
            }
        }
Esempio n. 11
0
        //// GET: UserProfiles/Details/5
        //public ActionResult Details(Guid? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    UserProfile userProfile = db.UserProfiles.Find(id);
        //    if (userProfile == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(userProfile);
        //}


        // GET: UserProfiles/Create
        public ActionResult Create()
        {
            UserProfile_Conf UserProfile_Conf;

            HomeController.UserAuth user = new HomeController.UserAuth();

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

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
                if (User.Identity.IsAuthenticated)
                {
                    proceed = true;
                }
                else
                {
                    proceed = false;
                }
                UserProfile_Conf = db.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == User.Identity.Name.ToString());
            }
            else
            {
                // Anonymous user without Authentication can still run this app
                proceed          = true;
                UserProfile_Conf = db.UserProfile_Conf.SingleOrDefault(x => x.NTUserName == "AnonymousUser");
            }


            // web.config debug setting
            ViewBag.debug  = HttpContext.IsDebuggingEnabled;
            ViewBag.agency = ConfigurationManager.AppSettings["agency"];
            ViewBag.ori    = ConfigurationManager.AppSettings["ori"];
            //ViewBag.useContractCity = Convert.ToBoolean(ConfigurationManager.AppSettings["useContractCity"] == "1" ? true : false);
            string useContractCity = ConfigurationManager.AppSettings["useContractCity"];

            ViewBag.useContractCity  = useContractCity;
            ViewBag.useContractEvent = ConfigurationManager.AppSettings["useContractEvent"];
            ViewBag.admin            = user.authorizedAdmin;
            UserProfile usrProf = new UserProfile();

            if (proceed && UserProfile_Conf == null)
            {
                if (useContractCity == "1")
                {
                    //create SelectListItem
                    usrProf.citiesList = dbl.ContractCities.
                                         Select(a => new SelectListItem
                    {
                        Text  = a.ContractCity.ToString().Trim(),                           // name to show in html dropdown
                        Value = a.ContractCity.ToString().Trim(),                           // value of html dropdown
                                                                                            //Selected = (a.City.ToString().Trim() == "ACAMPO")
                    }).ToList();
                }

                return(View(usrProf));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 12
0
        public ActionResult Edit([Bind(Include = "ID,Agency,ORI,Years,Assignment,AssignmentOther,ContractFundedPosition,ContractCity,ContractFundedEvent,citiesList")] UserProfile userProfile)
        {
            HomeController.UserAuth user = new HomeController.UserAuth();
            if (ConfigurationManager.AppSettings["requireGroupMembership"] == "true")
            {
                user = HomeController.AuthorizeUser(User.Identity.Name.ToString());

                if (!user.authorized && !user.authorizedAdmin)
                {
                    //return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
                    return(RedirectToAction("Unauthorized", "Home"));
                }
            }
            // web.config debug setting
            ViewBag.debug = HttpContext.IsDebuggingEnabled;
            ViewBag.admin = user.authorizedAdmin;
            string useContractCity = ConfigurationManager.AppSettings["useContractCity"];

            ViewBag.useContractCity  = useContractCity;
            ViewBag.useContractEvent = ConfigurationManager.AppSettings["useContractEvent"];

            if (useContractCity == "1")
            {
                //create SelectListItem
                userProfile.citiesList = dbl.ContractCities.
                                         Select(a => new SelectListItem
                {
                    Text  = a.ContractCity.ToString().Trim(),                           // name to show in html dropdown
                    Value = a.ContractCity.ToString().Trim(),                           // value of html dropdown
                }).ToList();
            }


            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(userProfile.Assignment))
                {
                    userProfile.AssignmentKey = Int32.Parse(userProfile.Assignment.Substring(0, userProfile.Assignment.IndexOf(' ')));
                    userProfile.Assignment    = userProfile.Assignment.Substring(userProfile.Assignment.IndexOf(' ') + 1, userProfile.Assignment.Length - userProfile.Assignment.IndexOf(' ') - 1);
                    if (userProfile.AssignmentKey != 10)
                    {
                        userProfile.AssignmentOther = null;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(userProfile.AssignmentOther))
                        {
                            ViewBag.ErrorOtherType = "Please enter a description for assignment";
                            return(View(userProfile));
                        }
                        if (userProfile.AssignmentOther.Length < 3)
                        {
                            ViewBag.ErrorOtherType = "Please enter at least 3 characters for this field.";
                            return(View(userProfile));
                        }
                    }
                }


                if (userProfile.ContractFundedPosition == true)
                {
                    if (string.IsNullOrEmpty(userProfile.ContractCity))
                    {
                        ViewBag.ErrorOtherType = "Please select a contracted city";
                        return(View(userProfile));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(userProfile.ContractCity))
                    {
                        ViewBag.ErrorOtherType = "Please select true for Position Contract Funded";
                        return(View(userProfile));
                    }
                }
                userProfile.Agency = ConfigurationManager.AppSettings["agency"];
                userProfile.ORI    = ConfigurationManager.AppSettings["ori"];

                db.Entry(userProfile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            // web.config debug setting
            //ViewBag.debug = HttpContext.IsDebuggingEnabled;
            return(View(userProfile));
        }
Esempio n. 13
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));
        }