Exemplo n.º 1
0
        public ActionResult Create([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 && User.Identity.IsAuthenticated)
            {
                //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    = User.Identity.Name,
                    UserProfileID = userProfile.ID
                }
                    );
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            //return RedirectToAction("Index", "Home");
            //return View(userProfile);
            return(View());
        }
Exemplo n.º 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;

                string   InitStrtSubDate = ConfigurationManager.AppSettings["InitStrtSubDate"];
                DateTime fromDate        = Convert.ToDateTime(InitStrtSubDate);
                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));
        }