public JsonResult RunAnalyze() { var resultsModel = new ResultsModel(); resultsModel.GenerateResults(); return resultsModel.GetCurrentResults().AsJsonResult(); }
public JsonResult Import(int rowId) { var currentElectionGuid = UserSession.CurrentElectionGuid; var file = Db.ImportFiles.SingleOrDefault( fi => fi.ElectionGuid == currentElectionGuid && fi.C_RowId == rowId); if (file == null) { throw new ApplicationException("File not found"); } var xml = GetXmlDoc(file); if (xml == null || xml.DocumentElement == null) { throw new ApplicationException("Invalid Xml file"); } var logHelper = new LogHelper(); ImportV1Base importer; var currentPeople = Db.People.Where(p => p.ElectionGuid == currentElectionGuid).ToList(); var personModel = new PeopleModel(); switch (xml.DocumentElement.Name) { case "Community": importer = new ImportV1Community(Db, file, xml , currentPeople , delegate(Person person) { personModel.SetCombinedInfoAtStart(person); person.ElectionGuid = currentElectionGuid; Db.People.Add(person); } , logHelper); break; case "Election": var currentElection = UserSession.CurrentElection; var currentLocation = UserSession.CurrentLocation; if (currentLocation == null) { currentLocation = Db.Locations.OrderBy(l => l.SortOrder).FirstOrDefault(l => l.ElectionGuid == currentElection.ElectionGuid); if (currentLocation == null) { throw new ApplicationException("An election must have a Location before importing."); } } EraseElectionContents(currentElection); importer = new ImportV1Election(Db, file, xml , currentElection , currentLocation , ballot => Db.Ballots.Add(ballot) , vote => Db.Votes.Add(vote) , currentPeople , person => { personModel.SetCombinedInfoAtStart(person); Db.People.Add(person); } , summary => Db.ResultSummaries.Add(summary) , logHelper ); break; default: throw new ApplicationException("Unexpected Xml file"); } importer.Process(); var resultsModel = new ResultsModel(); resultsModel.GenerateResults(); return importer.SendSummary(); }