public ActionResult Index() { var locationId = Request.QueryString["l"].AsInt(); if (locationId != 0 && (UserSession.CurrentLocation == null || locationId != UserSession.CurrentLocation.C_RowId)) { // switch to location, if allowed var switched = new ComputerModel().AddCurrentComputerIntoLocation(locationId); if (!switched) { return RedirectToAction("ChooseElection", "Dashboard"); } } var isSingle = UserSession.CurrentElection.IsSingleNameElection; var ballotModel = CurrentBallotModel; var ballotId = Request.QueryString["b"].AsInt(); if (ballotId == 0) { if (isSingle) { ballotModel.GetCurrentBallotInfo(); } } else { ballotModel.SetAsCurrentBallot(ballotId); } return isSingle ? View("BallotSingle", ballotModel) : View("BallotNormal", ballotModel); }
public void DetermineNextFreeComputerCode3_Test() { string[] list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray().Select(c=>c.ToString()).ToArray(); var sut = new ComputerModel(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("AA"); }
public void DetermineNextFreeComputerCode_Test() { var list = new[] {"A", "B"}; var sut = new ComputerModel(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("C"); }
public void DetermineNextFreeComputerCode5_Test() { var list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray().Select(c=>c.ToString()).ToList(); list.Add("AA"); list.Add("AB"); list.Add("AC"); list.Add("AE"); var sut = new ComputerModel(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("AD"); }
public object Pulse() { if (!UserSession.IsLoggedIn) { return(false); } var result2 = new Dictionary <string, object>(); var isStillAllowed = new ComputerModel().ProcessPulse(); //new ElectionModel().ProcessPulse(); var statusChanged = false; if (_infoFromClient != null) { statusChanged = _infoFromClient.Status != UserSession.CurrentElectionStatus; // switch (_infoFromClient.Context) // { // case "BeforeRollCall": // var rollcall = new RollCallModel(); // long newStamp; // result2.Add("MorePeople", rollcall.GetMorePeople(_infoFromClient.Stamp, out newStamp)); // result2.Add("NewStamp", newStamp); // break; // } } var newStatus = statusChanged ? new { // QuickLinks = new MenuHelper(_urlHelper).QuickLinks(), // Name = UserSession.CurrentElectionStatusName, Code = UserSession.CurrentElectionStatus, } : null; if (newStatus != null) { result2.Add("NewStatus", newStatus); } result2.Add("Active", isStillAllowed); result2.Add("PulseSeconds", isStillAllowed ? 0 : 60); // if 0, client will use its current pulse number return(result2); }
public bool JoinIntoElection(Guid wantedElectionGuid, Guid oldComputerGuid) { // don't use cache, go directly to database - cache is tied to current election var exists = Db.Election.Any(e => e.ElectionGuid == wantedElectionGuid); if (!exists) { return(false); } if (UserSession.CurrentElectionGuid == wantedElectionGuid) { return(true); } // switch this the whole environment to use this election UserSession.LeaveElection(true); // move into new election UserSession.CurrentElectionGuid = wantedElectionGuid; // assign new computer code var computerModel = new ComputerModel(); computerModel.GetComputerForMe(oldComputerGuid); string message; if (UserSession.IsGuestTeller) { message = "Guest teller joined into Election"; } else { message = "Teller (" + UserSession.MemberName + ") switched into Election"; new PublicHub().TellPublicAboutVisibleElections(); UpgradeOldData(); } new LogHelper().Add("{0} (Comp {1})".FilledWith(message, UserSession.CurrentComputerCode), true); return(true); }
public object Pulse() { var result2 = new Dictionary<string, object>(); var isStillAllowed = new ComputerModel().ProcessPulse(); new ElectionModel().ProcessPulse(); var statusChanged = false; if (_infoFromClient != null) { statusChanged = _infoFromClient.Status != UserSession.CurrentElectionStatus; switch (_infoFromClient.Context) { case "BeforeRollCall": var rollcall = new RollCallModel(); long newStamp; result2.Add("MorePeople", rollcall.GetMorePeople(_infoFromClient.Stamp, out newStamp)); result2.Add("NewStamp", newStamp); break; } } var newStatus = statusChanged ? new { QuickLinks = new MenuHelper(_urlHelper).QuickLinks(), Name = UserSession.CurrentElectionStatusName, Code = UserSession.CurrentElectionStatus, } : null; //VersionNum = new Random().Next(1, 100), if (newStatus != null) { result2.Add("NewStatus", newStatus); } result2.Add("Active", isStillAllowed); result2.Add("PulseSeconds", isStillAllowed ? 0 : 60); // if 0, client will use its current pulse number return result2; }
public void DetermineNextFreeComputerCode2_Test() { var list = new List<string> {"B", "C", "F", "G"}; var sut = new ComputerModel(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("A"); // fill hole list.AddRange(new[] { "A" }); list.Sort(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("D"); // fill hole list.AddRange(new [] {"D", "E", "H"}); list.Sort(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("J"); // skip I list.AddRange(new[]{"J","K"}); sut.DetermineNextFreeComputerCode(list).ShouldEqual("M"); // skip L list.AddRange(new[]{"M","N"}); sut.DetermineNextFreeComputerCode(list).ShouldEqual("P"); // skip O }
public void DetermineNextFreeComputerCode6_Test() { var list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray().Select(c=>c.ToString()).ToList(); for (var ch1 = 'A'; ch1 <= 'C'; ch1++) for (var ch2 = 'A'; ch2 <= 'Z'; ch2++) { list.Add("" + ch1 + ch2); } var sut = new ComputerModel(); sut.DetermineNextFreeComputerCode(list).ShouldEqual("DA"); }
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(); }
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; }