예제 #1
0
        ///<inheritdoc/>
        public void Update(int oldKey, OneVote element)
        {
            var oldVote = this.GetOne(oldKey);

            oldVote = element;
            this.db.SaveChanges();
        }
예제 #2
0
 public IActionResult UpdateVote(int oldId, [FromBody] OneVote vote)
 {
     if (this.oneVoteLogic.UpdateOneVote(oldId, vote))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
예제 #3
0
 ///<inheritdoc/>
 public bool UpdateOneVote(int oldId, OneVote newVote)
 {
     try
     {
         this.oneVoteRepo.Update(oldId, newVote);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #4
0
        public async Task <IActionResult> SubmitVote([FromBody] OneVote vote)
        {
            var associatedVote = this.oneVoteLogic.getAssociatedVote(vote);
            var userName       = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (await this.authLogic.HasRoleByName(userName, associatedVote.RequiredRole))
            {
                this.oneVoteLogic.CreateOneVote(vote, userName);
                await this.authLogic.RemoveUserFromRole(userName, associatedVote.RequiredRole);

                return(Ok());
            }
            return(Unauthorized());
        }
예제 #5
0
        /// <summary>
        /// Increments the associated values in the AllVotes entry, based on what this OneVote has voted for.
        /// </summary>
        /// <param name="vote">The OneVote object to be used to update the values in the AllVotes entry that belongs to it</param>
        void AddUsersChoiceToAllVotes(OneVote vote)
        {
            AllVotes allVoteToSaveChoise = this.allVotesLogic.GetOneVote(vote.VoteID);

            switch (vote.Choice)
            {
            case 0:
                allVoteToSaveChoise.YesVotes += 1;
                this.allVotesLogic.UpdateVote(allVoteToSaveChoise.VoteID, allVoteToSaveChoise);
                break;

            case 1:
                allVoteToSaveChoise.NoVotes += 1;
                this.allVotesLogic.UpdateVote(allVoteToSaveChoise.VoteID, allVoteToSaveChoise);
                break;

            default:
                allVoteToSaveChoise.AbsentionVotes += 1;
                this.allVotesLogic.UpdateVote(allVoteToSaveChoise.VoteID, allVoteToSaveChoise);
                break;
            }
        }
예제 #6
0
        ///<inheritdoc/>
        public bool CreateOneVote(OneVote vote, string name)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(vote.voteGroup) || vote.voteGroup.ToLower() == "string") //If we didn't get a votegroup from the frontend for the submitted vote, we look it up on backend side.
                {
                    var associatedVoteGroup = allVotesLogic.GetOneVote(vote.VoteID).voteGroup;
                    vote.voteGroup = associatedVoteGroup;
                }
                if (string.IsNullOrWhiteSpace(vote.submitterName) || vote.voteGroup.ToLower() == "string") // -||-
                {
                    vote.submitterName = name;
                }
                this.oneVoteRepo.Add(vote);
                this.AddUsersChoiceToAllVotes(vote);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #7
0
 ///<inheritdoc/>
 public void Add(OneVote element)
 {
     db.Add(element);
     db.SaveChanges();
 }
예제 #8
0
 ///<inheritdoc/>
 public AllVotes getAssociatedVote(OneVote input)
 {
     return(allVotesLogic.GetOneVote(input.VoteID));
 }
예제 #9
0
        ///<inheritdoc/>
        public bool canVote(IdentityUser user, OneVote vote)
        {
            var associatedVote = getAssociatedVote(vote);

            return(true); //placeholder
        }