示例#1
0
        public IVote VoteOnArtist(IVote vote)
        {
            IVote voteAdded = new Vote();

            IDataQuery query = new DataQuery();

            query.Where = string.Format("profileId={0} and songId={1} and battlId={2}", vote.ProfileId, vote.SongId, vote.BattlId);
            IVote result = _voteRepository.Find(query).FirstOrDefault();

            if (result != null)
            {
                vote.VoteId = result.VoteId;
                vote.Votes  = result.Votes + 1;
                voteAdded   = _voteRepository.Update(vote);
            }
            else
            {
                voteAdded = _voteRepository.Add(vote);
            }

            query.Where = string.Format("songId={0} and battlId={1}", vote.SongId, vote.BattlId);
            int resultTotal = CanGetVotesByWhere(query.Where).Sum(m => m.Votes);

            vote.Votes = resultTotal;

            return(voteAdded);
        }
示例#2
0
 public void ProcessRequest(HttpContext context)
 {
     if(null == _voteSource)
     {
         lock(_voteSourceLock)
         {
             if (null == _voteSource)
                 _voteSource = (IVote)HttpContext.Current.Application["VoteSource"];
         }
     }
     switch(context.Request.HttpMethod)
     {
         case "POST":
             var vi = ParsePayload(context.Request);
             context.Response.StatusCode = 202;
             context.Response.ContentType = "application/json";
             context.Response.Write("{status: \"Accepted\"");
             if(!string.IsNullOrEmpty(vi.DoorID))
             {
                 _voteSource.PostVote(vi);
             }
             break;
         default:
             var v = ParsePayload(context.Request);
             context.Response.ContentType = "text/plain";
             context.Response.Write(string.Format("Welcome to the Door Competition voting service. You can post your vote to this endpoint. DoorID: {0}",v.DoorID));
             break;
     }
 }
示例#3
0
 public DisplayController(IBallot ballot, ISeatService seatService, IMember member, ICouncilSession session, IVote vote)
 {
     _ballot      = ballot;
     _member      = member;
     _session     = session;
     _vote        = vote;
     _seatService = seatService;
 }
示例#4
0
文件: Game.cs 项目: aule/resistance
        public Game(IEnumerable<IPlayer> players, IEnumerable<IMission> missions, IVote votingSystem )
        {
            _players = (players ?? Enumerable.Empty<IPlayer>()).ToList();
            _missions = (missions ?? Enumerable.Empty<IMission>()).ToList();
            PlayerCount = _players.Count();
            _votingSystem = votingSystem;

            State = GameState.NotReady;
        }
示例#5
0
 static VoteService()
 {
     if (null == _voteSource)
     {
         lock (_voteSourceLock)
         {
             if (null == _voteSource)
                 _voteSource = (IVote)HttpContext.Current.Application["VoteSource"];
         }
     }
 }
示例#6
0
 public ProfileController(SignInManager <CreateUsers> signout,
                          IUserImages userimage,
                          IDatabaseRepository <UserImages> databaseuserimages,
                          IVote votes, IDatabaseRepository <Vote> voterepository)
 {
     this.signout            = signout;
     this.userimage          = userimage;
     this.databaseuserimages = databaseuserimages;
     this.votes          = votes;
     this.voterepository = voterepository;
 }
示例#7
0
        public V SendVoting(T Message, IVote <V> Vote)
        {
            if (OnVoting == null)
            {
                return(Vote.Result);
            }

            OnVoting?.Invoke(Message, Vote);

            return(Vote.Result);
        }
示例#8
0
        public async Task <VoteResult> VoteAsync(IVote vote)
        {
            try
            {
                var entity = VoteEntity.Create(vote);
                await _tableStorage.InsertAsync(entity);

                return(VoteResult.Accepted);
            }
            catch (Exception)
            {
                return(VoteResult.VoteIsAlreadyMade);
            }
        }
示例#9
0
        public static VoteEntity Create(IVote src)
        {
            var result = new VoteEntity
            {
                PartitionKey = GeneratePartitionKey(),
                RowKey       = GenerateRowKey(src.Email),
                Email        = src.Email,
                UserId       = src.UserId,
                Comment      = src.Comment,
                Created      = src.Created
            };

            result.SetOption(src.Option);

            return(result);
        }
示例#10
0
        public async Task <IActionResult> MyVote(MyVoteContract model)
        {
            //return Redirect(urlToRedirect);


            if (model.NotVoted())
            {
                return(RedirectToAction("Vote"));
            }

            if (string.IsNullOrEmpty(model.Token))
            {
                var user = this.GetUser();

                if (user == null)
                {
                    return(RedirectToAction("Signin"));
                }

                model.Email  = user.Email;
                model.UserId = user.UserId;
            }
            else
            {
                var token = await _voteTokensRepository.FindTokenAsync(model.Token);

                if (token == null)
                {
                    return(RedirectToAction("Signin"));
                }

                model.Email = token.Email;
            }

            IVote vote = await _votesRepository.GetAsync(model.Email);

            if (vote != null)
            {
                return(RedirectToAction("Success"));
            }



            await _votesRepository.VoteAsync(model);

            return(RedirectToAction("Success"));
        }
示例#11
0
        public HomeController(ILogger <HomeController> logger, IMemberRegister memberRegister, ICouncilSession session, IBallot ballot, IMember member, IVote vote, ISeatService seatService, IConfiguration configuration)
        {
            _configuration  = configuration;
            _memberRegister = memberRegister;
            _session        = session;
            _ballot         = ballot;
            _member         = member;
            _vote           = vote;
            _logger         = logger;
            _seatService    = seatService;

            model = new HomeIndexViewModel
            {
                Session = _session.GetActiveSession(),
                Ballot  = _ballot.GetActiveOrLast()
            };
        }
示例#12
0
        public static VoteEntity Create(IVote src)
        {
            var result = new VoteEntity
            {
                PartitionKey = GeneratePartitionKey(),
                RowKey       = GenerateRowKey(src.UserId),
                Email        = "---",
                UserId       = src.UserId,
                Option1      = src.Option1,
                Option2      = src.Option2,
                Option3      = src.Option3,
                Comment      = src.Comment,
                Created      = src.Created
            };

            return(result);
        }
示例#13
0
        /**
         * Alows the Student to place their vote on a Candidate after confirmation
         */
        public ActionResult Voting(int id)
        {
            string currentUserID = "";

            // Determine what role is the Student
            // capture the id of the Student that is voting for any roles
            if (TempData.ContainsKey("StudentRole"))
            {
                string studentRole = TempData["StudentRole"].ToString();

                if (studentRole.Equals("Candidate"))
                {
                    currentUserID           = TempData["CandidateID"].ToString();
                    TempData["CandidateID"] = currentUserID;
                    iVote = new Candidate();
                }
                else if (studentRole.Equals("Voter"))
                {
                    currentUserID       = TempData["VoterID"].ToString();
                    TempData["VoterID"] = currentUserID;
                    iVote = new Voter();
                }
                else if (studentRole.Equals("Admin"))
                {
                    currentUserID       = TempData["AdminID"].ToString();
                    TempData["AdminID"] = currentUserID;
                    iVote = new Admin();
                }
                TempData["StudentRole"] = studentRole;

                // Vote for the candidate by passing the candidate ID and the current user ID
                iVote.Vote(id, Convert.ToInt32(currentUserID));

                // TODO
                TempData["msg"] = "<script>alert('Change succesfully');</script>";

                // redirect to stats page
                return(RedirectToAction("Stats", "Home"));
            }

            return(RedirectToAction("Login", "Home"));
        }
示例#14
0
 public ImageController(IDatabaseRepository <UserImages> userimages,
                        IJsonCache <UserImages> cacheimage,
                        IDatabaseRepository <Vote> databasevote,
                        IDatabaseRepository <Comments> databasecomment,
                        IDatabaseRepository <Category> categoryrepository,
                        IJsonCache <Category> categorycache,
                        IVote updatevote,
                        IUserImages user,
                        IComments comments)
 {
     this.userimages         = userimages;
     this.cacheimage         = cacheimage;
     this.databasevote       = databasevote;
     this.updatevote         = updatevote;
     this.comments           = comments;
     this.databasecomment    = databasecomment;
     this.categoryrepository = categoryrepository;
     this.categorycache      = categorycache;
     this.user = user;
 }
示例#15
0
        public static Vote TransformToVote(IVote vote)
        {
            var newVote = new Vote
            {
                Bill         = Bill.TransformToBill(vote.Bill),
                BillId       = vote.BillId,
                Chamber      = vote.Chamber,
                Description  = vote.Description,
                Nomination   = vote.Nomination,
                NominationId = vote.NominationId,
                Question     = vote.Question,
                Result       = vote.Result,
                Source       = vote.Source,
                //Type = vote.Type,
                VoteCastedByLegislator = vote.VoteCastedByLegislator,
                VotedAt     = vote.VotedAt,
                VoteResults = vote.VoteResult
            };

            return(newVote);
        }
示例#16
0
        public ActionResult Index()
        {
            if (Authentication.User.Identity.IsAuthenticated)
            {
                // Determine what role is the Student
                if (TempData.ContainsKey("StudentRole"))
                {
                    string studentRole = TempData["StudentRole"].ToString();

                    if (studentRole.Equals("Candidate"))
                    {
                        iVote = new Candidate();
                    }
                    else if (studentRole.Equals("Voter"))
                    {
                        iVote = new Voter();
                    }
                    else if (studentRole.Equals("Admin"))
                    {
                        iVote = new Admin();
                    }
                    TempData["StudentRole"] = studentRole;

                    // if current user has voted, send them to the results page
                    if (iVote.hasCurrentUserVoted())
                    {
                        return(RedirectToAction("Stats", "Home"));
                    }
                }
                // allow them to see all the candidates to vote
                return(View(iCandidateProfile.ViewAllProfiles()));
            }

            else
            {
                //redirection to the action of login in the AccountController
                return(RedirectToAction("Login", "Home"));
            }
        }
示例#17
0
        public IVote VoteOnArtist(IVote vote)
        {
            IVote voteAdded = new Vote();

            IDataQuery query = new DataQuery();
            query.Where = string.Format("profileId={0} and songId={1} and battlId={2}", vote.ProfileId, vote.SongId, vote.BattlId);
            IVote result = _voteRepository.Find(query).FirstOrDefault();
            if (result != null)
            {
                vote.VoteId = result.VoteId;
                vote.Votes = result.Votes + 1;
                voteAdded = _voteRepository.Update(vote);
            }
            else
            {
                voteAdded = _voteRepository.Add(vote);
            }

            query.Where = string.Format("songId={0} and battlId={1}", vote.SongId, vote.BattlId);
            int resultTotal = CanGetVotesByWhere(query.Where).Sum(m => m.Votes);
            vote.Votes = resultTotal;

            return voteAdded;
        }
示例#18
0
 public void Remove(IVote entity)
 {
     base.Remove((StoryVote)entity);
 }
示例#19
0
文件: IVote.cs 项目: lanicon/Styx
 /// <summary>
 /// Vote 'yes' or 'ok' or 'allow' or 'accept'.
 /// </summary>
 public static void Accept(this IVote <Boolean> Vote)
 {
     Vote.VoteFor(true);
 }
示例#20
0
文件: IVote.cs 项目: lanicon/Styx
 /// <summary>
 /// Vote 'yes' or 'ok' or 'allow' or 'accept'.
 /// </summary>
 public static void Yes(this IVote <Boolean> Vote)
 {
     Vote.VoteFor(true);
 }
示例#21
0
文件: IVote.cs 项目: lanicon/Styx
 /// <summary>
 /// Vote 'no' or 'deny'.
 /// </summary>
 public static void Deny(this IVote <Boolean> Vote)
 {
     Vote.VoteFor(false);
 }
示例#22
0
 public virtual void AddVote(ISurvey pSurvey, IVote pVote)
 {
     throw new System.NotImplementedException();
 }
示例#23
0
 private Game PrepareGameInWaitingForMissionState(IEnumerable<IPlayer> players, IEnumerable<IMission> missions, IEnumerable<IPlayer> spies = null, IPlayer leader = null, IVote votingSystem = null)
 {
     Game game = PrepareGameInSelectLeaderState(players, missions, spies, votingSystem);
     game.SelectLeader(leader ?? game.Players.First());
     Assert.AreEqual(GameState.WaitingForMission, game.State);
     return game;
 }
示例#24
0
        public VoteController()
        {
            var bl = new BusinessManager();

            _vote = bl.GetVote();
        }
示例#25
0
    /// <summary>
    /// This method adds a vote to this survey and verifies if all votes were made. If this is the case a statChanged
    /// event with state finished will be fired. It will also check if the user still has open votes
    /// </summary>
    /// <param name="pVote">The vote to ass</param>
    public virtual void AddVote(IVote pVote)
    {
        if (_voteList.Count(x => x.User == pVote.User) < MaxVotesPerUser)
        {
            _voteList.Add(pVote);
            List<InteractionAttributes> changedAttributes = new List<InteractionAttributes> {InteractionAttributes.VoteList};
            OnModify(new InteractionEventArgs($"Survey votes changed [Id={Id}]", DateTime.Now, InteractionType.Survey));
        }

        // Is completed?
        if (_voteList.Count >= (MaxVotesPerUser*UserList.Count))
        {
            _isActive = false;
            ChangeState(InteractionState.Finished);
        }
    }
示例#26
0
 public void Add(IVote entity)
 {
     base.Add((StoryVote)entity);
 }
示例#27
0
 public VoteController(IVote vote_)
 {
     voteService = vote_;
 }
示例#28
0
 private Game PrepareFreshGame(IEnumerable<IPlayer> players, IEnumerable<IMission> missions, IVote votingSystem = null)
 {
     return new Game(players, missions, votingSystem);
 }
示例#29
0
 public virtual bool UpsertVote(IVote pVote)
 {
     throw new System.NotImplementedException();
 }
示例#30
0
 public static void RemoveVote(this IStory fromStory, IVote vote)
 {
     Check.Argument.IsNotNull(fromStory, "fromStory");
     Check.Argument.IsNotNull(vote, "vote");
     IoC.Resolve <IVoteRepository>().Remove(vote);
 }
示例#31
0
 public void AddVote(IVote vote)
 {
     _db.Insert(vote);
 }
示例#32
0
 public PollsController(UserManager <ApplicationUser> userManager, IPoll polls, IVote votes)
 {
     _userManager = userManager;
     _polls       = polls;
     _votes       = votes;
 }
 public PostsController(IPostService postService, IVote voteService)
 {
     this._postService = postService;
     this._voteService = voteService;
 }
示例#34
0
 private Game PrepareGameInSelectLeaderState(IEnumerable<IPlayer> players, IEnumerable<IMission> missions, IEnumerable<IPlayer> spies = null, IVote votingSystem = null)
 {
     Game game = PrepareFreshGame(players, missions, votingSystem);
     game.SelectSpies(spies);
     Assert.AreEqual(GameState.SelectingLeader, game.State);
     return game;
 }
示例#35
0
 public virtual void AddVote(IVote pOption)
 {
     throw new System.NotImplementedException();
 }
示例#36
0
 public V ProcessVoting(T1 Message1, T2 Message2, IVote <V> Vote)
 {
     Console.WriteLine("VotingTarget<T1, T2>" + Message1 + " / " + Message2 + " => true");
     return(default(V));
 }