public async Task <ActionResult> NextQuestion(int id) { try { Poll updatedPoll = await _pollRepository.SetNextQuestionAsync(id); if (updatedPoll != null) { PollResult message = PollHelper.GetPollResults(updatedPoll); await _hubContext.Clients.All.SendAsync(MessageTypes.LOAD_QUESTION, message); _logger.LogInformation(LoggingEvents.PollSetNextQuestion, "Poll {id} next question updated", id); return(Ok(updatedPoll)); } else { return(StatusCode(500, "Error occurred updating the database")); } } catch (PollNotFoundException e) { ApiStatusMessage a = ApiStatusMessage.CreateFromException(e); return(BadRequest(a)); } catch (PollAtLastQuestionException e) { ApiStatusMessage a = ApiStatusMessage.CreateFromException(e); return(BadRequest(a)); } catch (Exception e) { _logger.LogError(LoggingEvents.PollSetNextQuestion, "Error setting next question for poll {id}: Exception {ex}", id, e.Message); return(StatusCode(500, e.Message)); } }
public ActionResult SaveResults(PollResult poll, Project project) { SafeAdmission valid = ((List <SafeAdmission>)Session["admissions"]).Where(x => x.projectUrl == project.UrlCode).FirstOrDefault(); PollHelper.SavePoll(poll, valid, Request); ((List <SafeAdmission>)Session["admissions"]).Remove(valid); return(new JsonResult() { Data = null }); }
public ActionResult Index() { //237 //918,922 var users = PollHelper.GetFilteredPoll(237, new List <int>() { 918 }); PollHelper.ChartPollData("0057436918", users); Logger.InfoFormat("Path {0} Method {1}", HttpContext.Request.Url, HttpContext.Request.HttpMethod); return(View()); }
public void pollResult() { ForumPoll p = ctx.GetItem("poll") as ForumPoll; ForumBoard board = setCurrentBoard(p); set("topicId", p.TopicId); set("poll.Title", p.Title); set("poll.Question", p.Question); set("poll.Voters", p.VoteCount); set("lnkVoter", getVoterLink(p, board)); int colorCount = 6; int iColor = 1; IBlock opblock = getBlock("options"); for (int i = 0; i < p.OptionList.Length; i++) { PollHelper or = new PollHelper(p, p.OptionList.Length, i); opblock.Set("op.Text", p.OptionList[i]); opblock.Set("op.Id", (i + 1)); opblock.Set("op.ImgWidth", or.ImgWidth * 1); opblock.Set("op.Percent", or.VotesAndPercent); opblock.Set("op.ColorIndex", iColor); opblock.Next(); iColor++; if (iColor > colorCount) { iColor = 1; } } set("poll.ExpiryInfo", p.GetRealExpiryDate()); IBlock btnVote = getBlock("btnVote"); IBlock lblVoted = getBlock("lblVoted"); if (p.CheckHasVote(ctx.viewer.Id)) { lblVoted.Next(); } else if (p.IsClosed() == false) { btnVote.Next(); } }
/// <summary> /// Register the vote by updating the database /// and sending a message to all clients connected /// to the hub to inform interested parties /// </summary> /// <param name="pollId"></param> /// <param name="question"></param> /// <param name="answer"></param> private async Task RegisterVote(int pollId, int question, int answer) { // Register the vote in the database Poll updatedPoll = await _pollRepository.VoteAsync(pollId, question, answer); if (updatedPoll != null) { // then notify connected clients of the poll status using SignalR PollResult message = PollHelper.GetPollResults(updatedPoll); await _hubContext.Clients.All.SendAsync(MessageTypes.VOTE_RECEIVED, message); _logger.LogInformation(LoggingEvents.PollVoteRegistered, "Poll {id} vote registered", pollId); } }
public async Task <ActionResult> GetPollResults(int id) { var poll = await _pollRepository.GetPollAsync(id) ?? new Poll(); if (poll == null) { return(NotFound()); } PollResult result = PollHelper.GetPollResults(poll); _logger.LogInformation(LoggingEvents.GetPollResults, "Get poll results for {id}", id); return(Ok(result)); }
public async Task <ActionResult> ResetPoll(int id) { try { Poll poll = await _pollRepository.GetPollAsync(id); if (poll != null) { // Go through each question and reset the vote counts foreach (Question question in poll.Questions) { foreach (Answer answer in question.Answers) { answer.VoteCount = 0; } } poll.CurrentQuestion = 1; // Update the poll then notify connected clients of the poll status using SignalR poll = await _pollRepository.UpdatePollAsync(poll); PollResult message = PollHelper.GetPollResults(poll); await _hubContext.Clients.All.SendAsync(MessageTypes.RESET_POLL, message); _logger.LogInformation(LoggingEvents.ResetPoll, "Poll {id} has been reset", id); return(Ok(poll)); } else { return(StatusCode(500, "Error occurred updating the database")); } } catch (PollNotFoundException e) { ApiStatusMessage a = ApiStatusMessage.CreateFromException(e); return(BadRequest(a)); } catch (Exception e) { _logger.LogError(LoggingEvents.PollSetNextQuestion, "Error resetting poll {id}: Exception {ex}", id, e.Message); return(StatusCode(500, e.Message)); } }
public ActionResult GetPollDataById(int Id) { if (Session["user"] != null) { User user = (User)Session["user"]; var userProject = Db.Context.Projects .Where(x => x.Id == Id) .Select(x => x.UrlCode).FirstOrDefault(); if (userProject != null) { var data = PollHelper.ChartPollData(userProject, null); return(new JsonResult() { Data = data }); } } return(null); }
public ActionResult GetPoll(string poll) { if (PollHelper.CheckUrlProjectCode(poll)) { SafeAdmission valid = ((List <SafeAdmission>)Session["admissions"]).Where(x => x.projectUrl == poll).FirstOrDefault(); if (valid.projectUrl == poll) { var data = PollHelper.GetPoll(poll); return(new JsonResult() { Data = data }); } } return(new JsonResult() { Data = null }); }
public ActionResult Index(string poll) { if (PollHelper.CheckUrlProjectCode(poll)) { if (Session["admissions"] == null) { Session["admissions"] = new List <SafeAdmission>(); } SafeAdmission valid = ((List <SafeAdmission>)Session["admissions"]).Where(x => x.projectUrl == poll).FirstOrDefault(); if (valid != null && valid.Status) { return(View()); } else { return(RedirectToAction("RouteAccess", "Admission", new { projectUrl = poll })); } } return(Redirect("/")); }
public ActionResult SetTimer(string poll) { if (PollHelper.CheckUrlProjectCode(poll)) { SafeAdmission valid = ((List <SafeAdmission>)Session["admissions"]).Where(x => x.projectUrl == poll).FirstOrDefault(); if (valid.projectUrl == poll) { Project data = PollHelper.GetProjectByURL(poll); var timerValue = PollHelper.GetTimerValue(data.Id); //NEED TO IMPLEMENT return(new JsonResult() { Data = data }); } } return(new JsonResult() { Data = null }); }
/// <summary> /// Update the database poll record with the selected vote /// and notify any connected clients /// </summary> /// <param name="pollId"></param> /// <param name="question"></param> /// <param name="answer"></param> /// <returns></returns> public async Task <VoteResult> Vote(int pollId, int question, int answer) { VoteResult result = new VoteResult(); if (question < 1 || answer < 1) { result.StatusCode = 400; result.Errors.Add("Question and Answer index values must start at 1"); return(result); } try { // Register the vote in the database Poll updatedPoll = await _pollRepository.VoteAsync(pollId, question, answer); if (updatedPoll != null) { // then notify other connected clients of the poll status using SignalR PollResult message = PollHelper.GetPollResults(updatedPoll); await SendMessageToOthers(MessageTypes.VOTE_RECEIVED, message); result.StatusCode = 200; } else { result.StatusCode = 400; result.Errors.Add("Poll does not exist or is closed"); } } catch (Exception e) { result.StatusCode = 500; result.Errors.Add(e.Message); } return(result); }
public String GetRealExpiryDate() { return(PollHelper.GetRealExpiryDate(this)); }
public Boolean IsClosed() { return(PollHelper.IsClosed(this)); }