public async Task <PollChoice> DeletePollChoicesAsync(PollChoice pc) { _context.PollChoices.Remove(pc); await _context.SaveChangesAsync(); return(pc); }
public void OnPostFinishedQuestion() { if (Choices == null || Choices.Count == 0) { Error = "Error: No questions!"; } else { Poll myNewPoll = new Poll(); List <PollChoice> myPollChoice = new List <PollChoice>(); foreach (String A in Choices) { PollChoice myChoice = new PollChoice(); myChoice.mySelectedChoice = A; myPollChoice.Add(myChoice); } myNewPoll.PollQuestion = PollQuestion; myNewPoll.Name = Name; myNewPoll.PollCreationDate = DateTime.Now; myNewPoll.isFinished = false; myNewPoll.Choices = myPollChoice.ToArray(); myContext.myPolls.Add(myNewPoll); myContext.SaveChanges(); myPollChoice.Clear(); PollQuestion = ""; Name = ""; } }
public PollChoiceItemQuery WithChoice(PollChoice value = null, ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral, EntityOperator @operator = EntityOperator.Equal) { switch (mode) { case ArgumentEvaluationMode.IgnoreNeutral: if (Neutrals.Is(value)) { return(this); } break; case ArgumentEvaluationMode.Explicit: break; default: throw new NotSupportedEnumException(mode); } switch (@operator) { case EntityOperator.Equal: Entities = Entities.Where(pci => pci.Choice == value); return(this); case EntityOperator.NotEqual: Entities = Entities.Where(pci => pci.Choice != value); return(this); default: throw new NotSupportedEnumException(@operator); } }
public async Task <PollChoice> AddPollChoicesAsync(PollChoice pc) { await _context.PollChoices.AddAsync(pc); await _context.SaveChangesAsync(); return(pc); }
public PollQuery WithChoice(PollChoice value = null, ArgumentEvaluationMode mode = ArgumentEvaluationMode.IgnoreNeutral, CollectionOperator @operator = CollectionOperator.Equal, CollectionDirection direction = CollectionDirection.Any) { switch (mode) { case ArgumentEvaluationMode.IgnoreNeutral: if (Neutrals.Is(value)) { return(this); } break; case ArgumentEvaluationMode.Explicit: break; default: throw new NotSupportedEnumException(mode); } switch (@operator) { case CollectionOperator.Equal: switch (direction) { case CollectionDirection.Any: Entities = Entities.Where(p => p.Choices.Any(pc => pc == value)); return(this); case CollectionDirection.All: Entities = Entities.Where(p => p.Choices.All(pc => pc == value)); return(this); default: throw new NotSupportedEnumException(direction); } case CollectionOperator.NotEqual: switch (direction) { case CollectionDirection.Any: Entities = Entities.Where(p => p.Choices.Any(pc => pc != value)); return(this); case CollectionDirection.All: Entities = Entities.Where(p => p.Choices.All(pc => pc != value)); return(this); default: throw new NotSupportedEnumException(direction); } default: throw new NotSupportedEnumException(@operator); } }
public async Task ExecuteVote(int selectedId) { IsBusy = true; PollChoice choice = PollChoices[selectedId]; await pollDetailsService.Vote(choice); //VoteBusy = false; VoteCommand.ChangeCanExecute(); }
public async Task <PollChoice> UpdatePollChoicesAsync(PollChoice pc) { PollChoice oldpc = await _context.PollChoices.FindAsync(pc.ID); _context.Entry(oldpc).CurrentValues.SetValues(pc); await _context.SaveChangesAsync(); _context.ChangeTracker.Clear(); return(pc); }
public async Task <IActionResult> UpdateUserAsync(PollChoice pc) { try { await _pcBL.UpdatePollChoicesAsync(pc); return(NoContent()); } catch { return(StatusCode(500)); } }
public async Task Vote(PollChoice choice) { PollResult pollResult = new PollResult(); pollResult.ResultUuid = choice.Uuid.ToString(); string body = JsonConvert.SerializeObject(pollResult); Console.WriteLine(body); string resp = await App.ApiService.ApiRequest( "https://citizen.navispeed.eu/api/poll/poll/" + choice.PollUuid + "/results", HttpMethod.Post, body); Console.WriteLine(resp); }
public async Task <IActionResult> AddPollChoicesAsync([FromBody] PollChoice pc) { try { await _pcBL.AddPollChoicesAsync(pc); return(CreatedAtAction("AddPollChoices", pc)); } catch { return(StatusCode(400)); } }
public async Task <ActionResult> PollChoice(PollChoice newChoice) { if (ModelState.IsValid) { _pollContext.PollChoices.Add(newChoice); await _pollContext.SaveChangesAsync(); return(Ok(newChoice)); } else { return(BadRequest()); } }
public async Task <IActionResult> DeletePollAsync(PollChoice pc) { try { //var user = await _userBL.GetUserByIdAsync(id); await _pcBL.DeletePollChoicesAsync(pc); return(NoContent()); } catch { return(StatusCode(500)); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } for (int i = 0; i < SelectedAnswers.Count; ++i) { PollChoice pc = await _context.PollChoices.SingleOrDefaultAsync(c => c.ID == SelectedAnswers[i]); // grab poll choice from db that matches selected answer pc.VoteTally += 1; // increment the vote tally since the user selected it _context.Attach(pc).State = EntityState.Modified; // declare that the poll choice has been modified await _context.SaveChangesAsync(); // save changes to database } return(RedirectToPage("./VoteConfirmation")); }
public async Task <ActionResult> newPoll([FromBody] PollModel pollModel) { if (ModelState.IsValid) { PollQuestion pollQuestion = pollModel.Question; var newPoll = new PollQuestion() { Question = pollQuestion.Question, Status = pollQuestion.Status, Voted = pollQuestion.Voted }; IActionResult actionResult = await PollQuestion(newPoll); OkObjectResult okResult = actionResult as OkObjectResult; PollQuestion question = (PollQuestion)okResult.Value; IList <PollChoice> pollChoices = new List <PollChoice>(); pollChoices = pollModel.ListOfChoices; foreach (PollChoice choice in pollChoices) { var newChoice = new PollChoice() { Choice = choice.Choice, Votes = choice.Votes, PollId = question.PollId }; await PollChoice(newChoice); } return(Ok()); } else { return(BadRequest()); } }
public async Task <PollChoice> DeletePollChoicesAsync(PollChoice pc) { return(await _repo.DeletePollChoicesAsync(pc)); }
private void Button_Click_2( object sender, RoutedEventArgs e ) { PollChoice pc = (sender as Button).Tag as PollChoice; _polling.Remove(pc); }
private void AddNewValidator(PhantasmaKeys newValidator) { Timestamp startTime = simulator.CurrentTime; Timestamp endTime = simulator.CurrentTime.AddDays(1); var pollName = SystemPoll + ValidatorPollTag; var validators = (ValidatorEntry[])simulator.Nexus.RootChain.InvokeContract(simulator.Nexus.RootStorage, Nexus.ValidatorContractName, nameof(ValidatorContract.GetValidators)).ToObject(typeof(ValidatorEntry[])); var activeValidators = validators.Where(x => x.address != Address.Null); var activeValidatorCount = activeValidators.Count(); var choices = new PollChoice[activeValidatorCount + 1]; for (int i = 0; i < activeValidatorCount; i++) { choices[i] = new PollChoice() { value = validators[i].address.ToByteArray() }; } choices[activeValidatorCount] = new PollChoice() { value = newValidator.Address.ToByteArray() }; var serializedChoices = choices.Serialize(); //start vote for new validator simulator.BeginBlock(); simulator.GenerateCustomTransaction(owner, ProofOfWork.None, () => ScriptUtils.BeginScript(). AllowGas(owner.Address, Address.Null, 1, 9999). CallContract(ConsensusContractName, nameof(ConsensusContract.InitPoll), owner.Address, pollName, DomainSettings.ValidatorsOrganizationName, ConsensusMode.Majority, startTime, endTime, serializedChoices, 1). SpendGas(owner.Address). EndScript()); simulator.EndBlock(); for (int i = 0; i < activeValidatorCount; i++) { var validator = validatorKeyPairs[i]; //have each already existing validator vote on themselves to preserve the validator order simulator.BeginBlock(); simulator.GenerateCustomTransaction(validator, ProofOfWork.None, () => ScriptUtils.BeginScript(). AllowGas(validator.Address, Address.Null, 1, 9999). CallContract(ConsensusContractName, nameof(ConsensusContract.SingleVote), validator.Address, pollName, i). SpendGas(validator.Address). EndScript()); simulator.EndBlock(); } //skip until the voting is over simulator.TimeSkipDays(1.5); var votingRank = simulator.Nexus.RootChain.InvokeContract(simulator.Nexus.RootStorage, ConsensusContractName, nameof(ConsensusContract.GetRank), pollName, choices[activeValidatorCount].Serialize()).AsNumber(); //call SetValidator for each set validator address for (int i = 0; i <= activeValidatorCount; i++) { var validatorChoice = choices[i].value; ValidatorType validatorType = i < 2 ? Primary : Secondary; votingRank = simulator.Nexus.RootChain.InvokeContract(simulator.Nexus.RootStorage, ConsensusContractName, nameof(ConsensusContract.GetRank), pollName, validatorChoice).AsNumber(); simulator.BeginBlock(); var tx = simulator.GenerateCustomTransaction(owner, ProofOfWork.None, () => ScriptUtils.BeginScript(). AllowGas(owner.Address, Address.Null, 1, 9999). CallContract(ValidatorContractName, nameof(ValidatorContract.SetValidator), validatorChoice, votingRank, validatorType). SpendGas(owner.Address). EndScript()); simulator.EndBlock().First(); } }
public async Task <PollChoice> UpdatePollChoicesAsync(PollChoice pc) { return(await _repo.UpdatePollChoicesAsync(pc)); }
public async Task <PollChoice> AddPollChoicesAsync(PollChoice pc) { return(await _repo.AddPollChoicesAsync(pc)); }