Exemplo n.º 1
0
        public JsonResult RunAnalyze()
        {
            var resultsModel = new ResultsModel();

            resultsModel.GenerateResults();

            return(resultsModel.GetCurrentResults().AsJsonResult());
        }
Exemplo n.º 2
0
        private bool LoadXmlToDatabase()
        {
            _guidMap            = new Dictionary <Guid, Guid>();
            _locationsToProcess = new Dictionary <Location, XmlElement>();
            var start = DateTime.Now;

            //      using (var transaction = new TransactionScope())
            {
                try
                {
                    // the xml document is validated and ready to load

                    // Elements to be imported...

                    // election
                    // teller
                    // user - not imported. Current user becomes owner of imported election
                    // person
                    // location
                    // ballot
                    // vote
                    // log
                    // resultSummary
                    // result
                    // resultTie
                    // reason - not imported - embedded in the application. Included in export for reporting

                    LoadElectionInfo();

                    LoadTellers();

                    LoadLocations();

                    LoadPeople();

                    LoadBallots();

                    LoadResultInfo();

                    _hub.StatusUpdate("Running analysis...");

                    new ElectionModel().JoinIntoElection(_electionGuid, Guid.Empty);

                    var analyzer = new ResultsModel(null, _hub);
                    analyzer.GenerateResults();

                    _hub.StatusUpdate("Load complete ({0:N1} seconds)".FilledWith((DateTime.Now - start).TotalSeconds));
                }
                catch (DbUpdateException ex)
                {
                    throw new LoaderException("Cannot save", ex.LastException());
                }
                catch (DbEntityValidationException ex)
                {
                    var msgs = new List <string>();
                    foreach (var msg in ex.EntityValidationErrors.Where(v => !v.IsValid).Select(validationResult =>
                    {
                        var err = validationResult.ValidationErrors.First();
                        return("{0}: {1}".FilledWith(err.PropertyName, err.ErrorMessage));
                    }).Where(msg => !msgs.Contains(msg)))
                    {
                        msgs.Add(msg);
                    }
                    throw new LoaderException("Unable to save: " + msgs.JoinedAsString("; "));
                }

                //        transaction.Complete();
            }

            return(true);
        }