///<inheritdoc/> public void Update(int oldKey, OneVote element) { var oldVote = this.GetOne(oldKey); oldVote = element; this.db.SaveChanges(); }
public IActionResult UpdateVote(int oldId, [FromBody] OneVote vote) { if (this.oneVoteLogic.UpdateOneVote(oldId, vote)) { return(Ok()); } else { return(BadRequest()); } }
///<inheritdoc/> public bool UpdateOneVote(int oldId, OneVote newVote) { try { this.oneVoteRepo.Update(oldId, newVote); return(true); } catch (Exception) { return(false); } }
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()); }
/// <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; } }
///<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); } }
///<inheritdoc/> public void Add(OneVote element) { db.Add(element); db.SaveChanges(); }
///<inheritdoc/> public AllVotes getAssociatedVote(OneVote input) { return(allVotesLogic.GetOneVote(input.VoteID)); }
///<inheritdoc/> public bool canVote(IdentityUser user, OneVote vote) { var associatedVote = getAssociatedVote(vote); return(true); //placeholder }