예제 #1
0
        public virtual IActionResult DismissRolloverMessagePost([FromRoute] int id)
        {
            bool exists = _context.HetDistrictStatus.Any(a => a.DistrictId == id);

            // not found - return new status record
            if (!exists)
            {
                return(new ObjectResult(new HetsResponse(AnnualRolloverHelper.GetRecord(id, _context))));
            }

            // get record and update
            HetDistrictStatus status = _context.HetDistrictStatus
                                       .First(a => a.DistrictId == id);

            // ensure the process is complete
            if (status.DisplayRolloverMessage != null &&
                status.DisplayRolloverMessage == true &&
                status.ProgressPercentage != null &&
                status.ProgressPercentage == 100)
            {
                status.ProgressPercentage     = null;
                status.DisplayRolloverMessage = false;

                _context.SaveChanges();
            }

            // get status of current district
            return(new ObjectResult(new HetsResponse(AnnualRolloverHelper.GetRecord(id, _context))));
        }
예제 #2
0
        public virtual IActionResult RolloverStatusGet([FromRoute] int id)
        {
            bool exists = _context.HetDistrict.Any(a => a.DistrictId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get status of current district
            return(new ObjectResult(new HetsResponse(AnnualRolloverHelper.GetRecord(id, _context))));
        }
예제 #3
0
        public virtual IActionResult AnnualRolloverGet([FromRoute] int id)
        {
            bool exists = _context.HetDistrict.Any(a => a.DistrictId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // determine the current fiscal year
            DateTime fiscalStart;

            if (DateTime.UtcNow.Month == 1 || DateTime.UtcNow.Month == 2 || DateTime.UtcNow.Month == 3)
            {
                fiscalStart = new DateTime(DateTime.UtcNow.AddYears(-1).Year, 4, 1);
            }
            else
            {
                fiscalStart = new DateTime(DateTime.UtcNow.Year, 4, 1);
            }

            // get record and ensure it isn't already processing
            HetDistrictStatus status = AnnualRolloverHelper.GetRecord(id, _context);

            if (status == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            if (status.CurrentFiscalYear == fiscalStart.Year)
            {
                // return - cannot rollover again
                return(new ObjectResult(status));
            }

            if (status.DisplayRolloverMessage == true ||
                (status.ProgressPercentage != null && status.ProgressPercentage > 0))
            {
                // return already active
                return(new ObjectResult(status));
            }

            // serialize scoring rules from config into json string
            IConfigurationSection scoringRules = _configuration.GetSection("SeniorityScoringRules");
            string seniorityScoringRules       = GetConfigJson(scoringRules);

            // get connection string
            string connectionString = GetConnectionString();

            // queue the job
            BackgroundJob.Enqueue(() => AnnualRolloverHelper.AnnualRolloverJob(null, id, seniorityScoringRules, connectionString));

            // get counts for this district
            int localAreaCount = _context.HetLocalArea
                                 .Count(a => a.ServiceArea.DistrictId == id);

            int equipmentCount = _context.HetDistrictEquipmentType
                                 .Count(a => a.DistrictId == id);

            // update status - job is kicked off
            status.LocalAreaCount             = localAreaCount;
            status.DistrictEquipmentTypeCount = equipmentCount;
            status.ProgressPercentage         = 1;
            status.DisplayRolloverMessage     = true;

            _context.HetDistrictStatus.Update(status);
            _context.SaveChanges();

            return(new ObjectResult(status));
        }