示例#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
        }