示例#1
0
        public async Task <ActionResult> SubmissionStats(Submissions submission, int?sid, DateTime startDate, DateTime?endDate)
        {
            UserAuth user   = new UserAuth();
            DataSet  dsStop = new DataSet();

            user = AuthorizeUser(User.Identity.Name.ToString());

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

            if (ModelState.IsValid)
            {
                UserProfile_Conf uid = db.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.submissionEndDate = endDate;
                DOJSubmitController dOJSubmit = new DOJSubmitController();

                //Make sure the connection to DOJ url is available
                //DOJSubmitController.connectionStatus connectStat = dOJSubmit.HTTP_Connection();
                //if (!connectStat.connected)
                //{
                //    TempData["CustomError"] = connectStat.error;
                //    return RedirectToAction("Index", "StopsSubmission", sid);
                //}

                bool connected = dOJSubmit.HTTP_Connection2();
                if (!connected)
                {
                    TempData["CustomError"] = "Can not connect to DOJ endpoint\r\n";
                    return(RedirectToAction("Index", "StopsSubmission", sid));
                }
                // If submission record in this date range is In Progress do not allow another submission
                Submissions submissionInProgress = entitiesdb.Submissions
                                                   .Where(x => x.StartDate == startDate && x.EndDate == endDate && x.Status == "In Progress")
                                                   .FirstOrDefault();

                if (submissionInProgress != null)
                {
                    TempData["CustomError"] = "A submission in this date range is already 'In Progress'";
                    return(RedirectToAction("Index", "StopsSubmission", sid));
                }

                if (sid != 0)
                {
                    Submissions submissionOld = entitiesdb.Submissions.Find(sid);
                    if (submissionOld.TotalHTTPErrors == 0 || submissionOld.TotalHTTPErrors == null)
                    {
                        submission = submissionOld;
                    }
                }
                submission.StartDate = startDate;
                if (endDate < submission.StartDate || endDate > DateTime.Now)
                {
                    TempData["CustomError"] = "Invalid Date Range";
                    return(RedirectToAction("Index", "StopsSubmission", sid));
                }
                else
                {
                    bool fixedFlag = false;

                    SQLDBDataAccessorClass sql = new SQLDBDataAccessorClass();
                    string sqlStr = "";
                    sqlStr = "Select * from Stops" +
                             " Where SubmissionsID = " + submission.ID +
                             " and JsonSubmissions is not null " +
                             " and Right(JsonSubmissions, 15) like '%true%'";
                    dsStop = sql.mds_ExecuteQuery(sqlStr, "StopsTbl");
                    int rowsCount = dsStop.Tables["StopsTbl"].Rows.Count;


                    if (rowsCount != 0)
                    {
                        fixedFlag = true;
                    }

                    ViewBag.fixedFlag = fixedFlag;

                    // Change the status of the current submission record, with edited Stops, to "resumbit",
                    // and create a new submission record to Resubmit all the fixed records again
                    if (rowsCount != 0)
                    {
                        submission.Status = "Resubmit";
                        if (ModelState.IsValid)
                        {
                            entitiesdb.Entry(submission).State = EntityState.Modified;
                            await entitiesdb.SaveChangesAsync();
                        }
                        Submissions newSubmission = new Submissions();
                        newSubmission.StartDate = submission.StartDate;
                        submission = newSubmission;
                    }
                    submission.Status        = "In Progress";
                    submission.DateSubmitted = DateTime.Now;
                    submission.EndDate       = endDate;

                    var state = await dOJSubmit.GetStops(submission);

                    entitiesdb.Entry(submission).State = state;

                    if (submission.TotalProcessed == submission.TotalSuccess)
                    {
                        submission.Status = "Finished";
                    }
                    else
                    {
                        submission.Status     = "Pending Fixes";
                        submission.statusMsgs = entitiesdb.StatusMessage_JSON_vw
                                                .Where(x => x.submissionID == submission.ID && x.StopStatus != "success" && x.StopStatus != "postSubRedact")
                                                .ToList();
                        submission.subList = entitiesdb.Submissions.ToList();
                    }
                    //If ModelState.IsValid is not True this might
                    //cause submission to stay in 'In Progress' status
                    //
                    //if (ModelState.IsValid)
                    //{
                    //state = entitiesdb.Entry(submission).State;
                    //entitiesdb.Entry(submission).State = EntityState.Modified;
                    entitiesdb.SaveChanges();
                    ViewBag.submissionID = submission.ID;

                    //}
                }
            }
            else
            {
                TempData["CustomError"] = "End Date is required.";
            }


            return(RedirectToAction("Index", "StopsSubmission", submission.ID));
        }
        public async Task <ActionResult> SubmissionStats(Submissions submission, int?sid, DateTime startDate, DateTime?endDate)
        {
            UserAuth user = new UserAuth();

            user = AuthorizeUser(User.Identity.Name.ToString());

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

            if (ModelState.IsValid)
            {
                UserProfile_Conf uid = db.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.submissionEndDate = endDate;
                DOJSubmitController dOJSubmit = new DOJSubmitController();

                //Make sure the connection to DOJ url is available
                DOJSubmitController.connectionStatus connectStat = dOJSubmit.HTTP_Connection();
                if (!connectStat.connected)
                {
                    TempData["CustomError"] = connectStat.error;
                    return(RedirectToAction("Index", "StopsSubmission", sid));
                }

                // If submission record in this date range is In Progress do not allow another submission
                Submissions submissionInProgress = entitiesdb.Submissions
                                                   .Where(x => x.StartDate == startDate && x.EndDate == endDate && x.Status == "In Progress")
                                                   .FirstOrDefault();

                if (submissionInProgress != null)
                {
                    TempData["CustomError"] = "A submission in this date range is already 'In Progress'";
                    return(RedirectToAction("Index", "StopsSubmission", sid));
                }

                if (sid != 0)
                {
                    Submissions submissionOld = entitiesdb.Submissions.Find(sid);
                    submission = submissionOld;
                }
                submission.StartDate = startDate;
                if (endDate < submission.StartDate || endDate > DateTime.Now)
                {
                    TempData["CustomError"] = "Invalid Date Range";
                    return(RedirectToAction("Index", "StopsSubmission", sid));
                }
                else
                {
                    //int stopsCount = entitiesdb.StopOfficerIDDateTime_JSON_vw.ToList()
                    //        .Where(x => submission.StartDate <= Convert.ToDateTime(x.stopDate) && Convert.ToDateTime(x.stopDate) < submission.EndDate).Count();
                    //ViewBag.totalToBeSubmitted = stopsCount;
                    bool        fixedFlag = false;
                    List <Stop> Stops     = db.Stop.Where(x => x.SubmissionsID == submission.ID).ToList();
                    // Check if any records have been edited
                    foreach (Stop st in Stops)
                    {
                        JObject submissionO    = JObject.Parse(st.JsonSubmissions);
                        JObject lastSubmission = (JObject)submissionO["SubmissionInfo"].Last();
                        int     submissionID   = (int)lastSubmission["submissionID"];
                        bool    edited         = (bool)lastSubmission["edited"];
                        if (submissionID == submission.ID && edited == true)
                        {
                            fixedFlag = true;
                            break;
                        }
                    }
                    ViewBag.fixedFlag = fixedFlag;

                    // Change the status of the current submission record, with edited Stops, to "resumbit",
                    // and create a new submission record to Resubmit all the fixed records again
                    if (Stops.Count != 0)
                    {
                        submission.Status = "Resubmit";
                        if (ModelState.IsValid)
                        {
                            entitiesdb.Entry(submission).State = EntityState.Modified;
                            await entitiesdb.SaveChangesAsync();
                        }
                        Submissions newSubmission = new Submissions();
                        newSubmission.StartDate = submission.StartDate;
                        submission = newSubmission;
                    }
                    submission.Status        = "In Progress";
                    submission.DateSubmitted = DateTime.Now;
                    submission.EndDate       = endDate;

                    var state = await dOJSubmit.GetStops(submission);

                    entitiesdb.Entry(submission).State = state;

                    if (submission.TotalProcessed == submission.TotalSuccess)
                    {
                        submission.Status = "Finished";
                    }
                    else
                    {
                        submission.Status     = "Pending Fixes";
                        submission.statusMsgs = entitiesdb.StatusMessage_JSON_vw
                                                .Where(x => x.submissionID == submission.ID && x.StopStatus != "success")
                                                .ToList();
                        submission.subList = entitiesdb.Submissions.ToList();
                    }

                    if (ModelState.IsValid)
                    {
                        state = entitiesdb.Entry(submission).State;
                        await entitiesdb.SaveChangesAsync();

                        ViewBag.submissionID = submission.ID;
                    }
                }
            }
            else
            {
                TempData["CustomError"] = "End Date is required.";
            }


            return(RedirectToAction("Index", "StopsSubmission", submission.ID));
        }