コード例 #1
0
    public JsonResult Create()
    {
      if (UserSession.IsGuestTeller)
      {
        return new
                 {
                   Success = false,
                   Message = "Not authorized"
                 }.AsJsonResult();
      }

      // create an election for this ID
      // create a default Location
      // assign all of these to this person and computer

      var election = new Election
                       {
                         Convenor = "[Convenor]",
                         ElectionGuid = Guid.NewGuid(),
                         Name = "[New Election]",
                         ElectionType = "LSA",
                         ElectionMode = ElectionMode.Normal,
                         TallyStatus = ElectionTallyStatusEnum.NotStarted,
                         NumberToElect = 9,
                         NumberExtra = 0,
                         CanVote = CanVoteOrReceive.All,
                         CanReceive = CanVoteOrReceive.All
                       };
      Db.Elections.Add(election);
      Db.SaveChanges();

      new ElectionStatusSharer().SetStateFor(election);

      var join = new JoinElectionUser
                   {
                     ElectionGuid = election.ElectionGuid,
                     UserId = UserSession.UserGuid
                   };
      Db.JoinElectionUsers.Add(join);


      var mainLocation = new Location
                           {
                             Name = "Main Location",
                             LocationGuid = Guid.NewGuid(),
                             ElectionGuid = election.ElectionGuid,
                             SortOrder = 1
                           };
      Db.Locations.Add(mainLocation);

      Db.SaveChanges();

      UserSession.CurrentElection = election;

      var computerModel = new ComputerModel();
      computerModel.AddCurrentComputerIntoElection(election.ElectionGuid);
      computerModel.AddCurrentComputerIntoLocation(mainLocation.C_RowId);

      return new
               {
                 Success = true
               }.AsJsonResult();
    }
コード例 #2
0
    public bool JoinIntoElection(Guid wantedElectionGuid)
    {
      var election = Db.Elections.SingleOrDefault(e => e.ElectionGuid == wantedElectionGuid);
      if (election == null)
      {
        return false;
      }

      UserSession.CurrentElection = election;

      var computerModel = new ComputerModel();
      computerModel.AddCurrentComputerIntoElection(election.ElectionGuid);

      var firstLocation =
        Db.Locations.OrderBy(l => l.SortOrder).FirstOrDefault(l => l.ElectionGuid == election.ElectionGuid);
      // default to top location
      if (firstLocation != null)
      {
        computerModel.AddCurrentComputerIntoLocation(firstLocation.C_RowId);
      }

      var message = UserSession.IsGuestTeller
                      ? "Guest teller joined into Election"
                      : "Teller (" + UserSession.MemberName + ") switched into Election";

      new LogHelper().Add(message);

      return true;
    }