public ActionResult RunEngine(int submissionCycleId)
        {
            SubmissionCycle submissionCycle = _submissionCycleService.GetSubmissionCycle(submissionCycleId);

            if (submissionCycle == null)
            {
                string strMessage = $"Collection cycle with id {submissionCycleId} not found.";
                _loggingService.LogErrorMessage(strMessage);
                throw new InvalidOperationException(strMessage);
            }

            // TODO: Validate the user's access to district, action, school year
            // todo: all security

            ValidationReportSummary summary = _rulesEngineService.SetupValidationRun(
                submissionCycle,
                submissionCycle.CollectionId);

            HostingEnvironment.QueueBackgroundWorkItem(
                cancellationToken => _rulesEngineService.RunValidationAsync(
                    submissionCycle,
                    summary.ValidationReportSummaryId));

            return(Json(summary));
        }
        private void PopulateDropDownLists(SubmissionCycle submissionCycle = null)
        {
            List <SelectListItem> schoolYears = _submissionCycleService.GetSchoolYearsSelectList(submissionCycle);
            var ruleCollections = _rulesEngineService.GetCollections().Select(c => c.CollectionId);

            ViewData["schoolYears"]     = schoolYears;
            ViewData["RuleCollections"] = ruleCollections;
        }
        public ActionResult AddSubmissionCycle()
        {
            PopulateDropDownLists();
            var submissionCycle = new SubmissionCycle {
                StartDate = DateTime.Now, EndDate = DateTime.Now
            };

            return(PartialView("Partials/SubmissionCycleEditModal", submissionCycle));
        }
        public ActionResult SaveSubmissionCycle(SubmissionCycle submissionCycle)
        {
            if (submissionCycle.EndDate < submissionCycle.StartDate)
            {
                ModelState.AddModelError("EndDate", "End Date needs to be later than Start Date");
            }

            // We should not let the user add a collection cycle with the same school year and collectionId combination
            // that already exists in the database, or set the school year and collectionId of an existing cycle
            // to ones of another existing collection cycle.
            SubmissionCycle duplicate = _submissionCycleService.SchoolYearCollectionAlreadyExists(submissionCycle);

            if (duplicate != null && (submissionCycle.Id == 0 || submissionCycle.Id != duplicate.Id))
            {
                ModelState.AddModelError("CollectionId", "A collection cycle with this School Year and Collection already exists.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _submissionCycleService.SaveSubmissionCycle(submissionCycle);
                    var submissionCycles = _submissionCycleService.GetSubmissionCycles();
                    return(RedirectToAction("Index", new { tab = "submissioncycles" }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("General Error", ex.Message);
                    PopulateDropDownLists(submissionCycle);
                    return(PartialView("Partials/SubmissionCycleEditModal", submissionCycle));
                }
            }
            else
            {
                PopulateDropDownLists(submissionCycle);
                return(PartialView("Partials/SubmissionCycleEditModal", submissionCycle));
            }
        }