Beispiel #1
0
        public ActionResult DoPublishingProcessing(ManageExcelUploadsAndEtlViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                throw new SitkaDisplayErrorException("Not expecting model state to be bad; not running publishing processing.");
            }

            bool     wasErrorDuringProcessing = false;
            DateTime startTime = DateTime.Now;

            try
            {
                DoPublishingSql();
                var tabularImports           = HttpRequestStorage.DatabaseEntities.TabularDataImports.ToList();
                var processedDateTime        = DateTime.Now;
                var latestImportForNortheast = TabularDataImport.GetLatestImportProcessingForGivenType(tabularImports, TabularDataImportTableType.LoaNortheast);
                var latestImportForSoutheast = TabularDataImport.GetLatestImportProcessingForGivenType(tabularImports, TabularDataImportTableType.LoaSoutheast);
                if (latestImportForSoutheast != null)
                {
                    latestImportForSoutheast.LastProcessedDate   = processedDateTime;
                    latestImportForSoutheast.LastProcessedPerson = CurrentPerson;
                }

                if (latestImportForNortheast != null)
                {
                    latestImportForNortheast.LastProcessedDate   = processedDateTime;
                    latestImportForNortheast.LastProcessedPerson = CurrentPerson;
                }
                HttpRequestStorage.DatabaseEntities.SaveChanges(CurrentPerson);
            }
            catch (Exception e)
            {
                SetInfoForDisplay($"Problem executing Publishing: {e.Message}");
                wasErrorDuringProcessing = true;
            }

            DateTime endTime              = DateTime.Now;
            var      elapsedTime          = endTime - startTime;
            string   processingTimeString = GetTaskTimeString("Publishing", elapsedTime);

            if (!wasErrorDuringProcessing)
            {
                SetMessageForDisplay($"Publishing Processing completed Successfully.<br/>{processingTimeString}");
            }
            else
            {
                // Apparently at the moment we can only have one error/warning, so since I want TWO messages, resorting to
                // an error and a warning.
                SetErrorForDisplay($"Publishing Processing had problems.<br/>{processingTimeString}");
            }
            return(RedirectToAction(new SitkaRoute <ExcelUploadController>(x => x.ManageExcelUploadsAndEtl())));
        }
        public ManageExcelUploadsAndEtlViewData(Person currentPerson,
                                                Models.FirmaPage firmaPage,
                                                string uploadLoaNortheastSpreadSheetUrl,
                                                string uploadLoaSoutheastSpreadSheetUrl,
                                                string doPublishingProcessingPostUrl,
                                                string uploadLoaFormID,
                                                List <TabularDataImport> tabularDataImports
                                                ) : base(currentPerson, firmaPage)
        {
            PageTitle = $"Upload Loa Tabular Data";
            UploadLoaNortheastSpreadSheetUrl = uploadLoaNortheastSpreadSheetUrl;
            UploadLoaSoutheastSpreadSheetUrl = uploadLoaSoutheastSpreadSheetUrl;
            UploadLoaFormID = uploadLoaFormID;
            DoPublishingProcessingPostUrl = doPublishingProcessingPostUrl;

            LatestTabularDataImportForLoaNortheast = TabularDataImport.GetLatestImportProcessingForGivenType(tabularDataImports, TabularDataImportTableType.LoaNortheast);
            LatestTabularDataImportForLoaSoutheast = TabularDataImport.GetLatestImportProcessingForGivenType(tabularDataImports, TabularDataImportTableType.LoaSoutheast);
        }
Beispiel #3
0
        private ActionResult DoLoaExcelImportForFileStream(Stream excelFileAsStream, string optionalOriginalFilename, bool isNortheast)
        {
            DateTime startTime = DateTime.Now;
            var      errorList = new List <string>();
            List <LoaStageImport> loaStages;

            try
            {
                loaStages = LoaStageImportsHelper.LoadLoaStagesFromXlsFile(excelFileAsStream, LoaNortheastExcelFileHeaderRowOffset, errorList);
            }
            catch (Exception ex)
            {
                return(Common_LoadFromXls_ExceptionHandler(excelFileAsStream, optionalOriginalFilename, ex));
            }

            if (isNortheast)
            {
                var previousLoaStagesFromNortheast =
                    HttpRequestStorage.DatabaseEntities.LoaStages.Where(x => x.IsNortheast).ToList();
                previousLoaStagesFromNortheast.ForEach(x => x.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }
            else
            {
                var previousLoaStagesFromSoutheast =
                    HttpRequestStorage.DatabaseEntities.LoaStages.Where(x => x.IsSoutheast).ToList();
                previousLoaStagesFromSoutheast.ForEach(x => x.DeleteFull(HttpRequestStorage.DatabaseEntities));
            }



            var countAdded = 0;

            foreach (var loaStageImport in loaStages)
            {
                if (!string.IsNullOrEmpty(loaStageImport.ProjectID))
                {
                    var loaStage = new LoaStage(loaStageImport, isNortheast);
                    countAdded = countAdded + 1;
                    HttpRequestStorage.DatabaseEntities.LoaStages.Add(loaStage);
                }
            }

            HttpRequestStorage.DatabaseEntities.SaveChanges(CurrentPerson);


            DateTime endTime          = DateTime.Now;
            var      elapsedTime      = endTime - startTime;
            string   importTimeString = GetTaskTimeString("Import", elapsedTime);

            // Record that we uploaded
            var tabularDataImportTableTypeID = isNortheast ? TabularDataImportTableType.LoaNortheast.TabularDataImportTableTypeID : TabularDataImportTableType.LoaSoutheast.TabularDataImportTableTypeID;
            var newTabularDataImport         = new TabularDataImport(tabularDataImportTableTypeID);

            newTabularDataImport.UploadDate   = endTime;
            newTabularDataImport.UploadPerson = CurrentPerson;
            HttpRequestStorage.DatabaseEntities.TabularDataImports.Add(newTabularDataImport);
            HttpRequestStorage.DatabaseEntities.SaveChanges(CurrentPerson);

            SetMessageForDisplay($"{countAdded.ToGroupedNumeric()} LOA records were successfully imported to database. </br>{importTimeString}.");
            if (errorList.Any())
            {
                SetInfoForDisplay(string.Join("<br>", errorList));
            }

            // This is the right thing to return, since this starts off in a modal dialog
            return(new ModalDialogFormJsonResult());
        }