public Exporter Export()
        {
            // collect all the info
            _election = Db.Elections.SingleOrDefault(e => e.ElectionGuid == _electionGuid);

            var logger = new LogHelper(_electionGuid);
            logger.Add("Export to file started");

            if (_election == null) return null;

            var locations = Db.Locations.Where(l => l.ElectionGuid == _electionGuid);
            var computers = Db.Computers.Where(c => c.ElectionGuid == _electionGuid);

            var people = Db.People.Where(p => p.ElectionGuid == _electionGuid);
            var tellers = Db.Tellers.Where(t => t.ElectionGuid == _electionGuid);
            var results = Db.Results.Where(r => r.ElectionGuid == _electionGuid);
            var resultSummaries = Db.ResultSummaries.Where(r => r.ElectionGuid == _electionGuid);
            var resultTies = Db.ResultTies.Where(r => r.ElectionGuid == _electionGuid);
            var logs = Db.C_Log.Where(log => log.ElectionGuid == _electionGuid);

            var joinElectionUsers = Db.JoinElectionUsers.Where(j => j.ElectionGuid == _electionGuid);
            var users = Db.Users.Where(u => joinElectionUsers.Select(j => j.UserId).Contains(u.UserId));

            var ballots = Db.Ballots.Where(b => locations.Select(l => l.LocationGuid).Contains(b.LocationGuid));
            var votes = Db.Votes.Where(v => ballots.Select(b => b.BallotGuid).Contains(v.BallotGuid));

            var site = new SiteInfo();

            var blob = new
                {
                    Exported = DateTime.Now.ToString("o"),
                    ByUser = UserSession.MemberName,
                    UserEmail = UserSession.MemberEmail,
                    Server = site.ServerName,
                    Environment = site.CurrentEnvironment,
                    // elements
                    election = ExportElection(_election),
                    resultSummary = ExportResultSummaries(resultSummaries),
                    result = ExportResults(results),
                    resultTie = ExportResultTies(resultTies),
                    teller = ExportTellers(tellers),
                    user = ExportUsers(users),
                    location = ExportLocationComputerBallotVote(locations, computers, ballots, votes, logs),
                    person = ExportPeople(people),
                    reason = ExportReasons(),
                    //log = ExportLogs(logs)
                };

            var exportName = string.Format("{0} {1}.TallyJ",
                                           _election.DateOfElection.GetValueOrDefault(DateTime.Today)
                                                    .ToString("yyyy-MM-dd"),
                                           _election.Name);

            return new Exporter(blob, "TallyJ2", exportName);
        }
    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();
    }