public void SendPoll(PollChoices pollChoices)
        {
            Debug.Log("SendPoll");
            var serialized = JsonConvert.SerializeObject(pollChoices);

            _Socket.Emit(Command.LAUNCH_POLL, new JSONObject(serialized));
        }
        public async Task ExecuteLoadChoicesCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                PollChoices.Clear();
                var items = await pollDetailsService.GetItemsAsync();

                foreach (var item in items)
                {
                    PollChoices.Add(item);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION");
                Console.WriteLine(ex);
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }

            IsBusy = false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Call this method to start an audience poll (events).
        /// At the end, a callback will take care of instantiating the event in the arena.
        /// </summary>
        /// <param name="eventA">First event</param>
        /// <param name="eventB">Second event</param>
        /// <param name="pollingTime">Polling time in seconds</param>
        public void StartPoll(Events.EventID eventA, Events.EventID eventB, int pollingTime)
        {
            var pollEventA = new messages.Event {
                id = (int)eventA, votes = 0
            };
            var pollEventB = new messages.Event {
                id = (int)eventB, votes = 0
            };

            var poll = new PollChoices()
            {
                events = new List <Event> {
                    pollEventA, pollEventB
                },
                deadline = "", // not used
                duration = pollingTime,
            };

            _AudienceInteractionManager?.SendPoll(poll);
            StartCoroutine("StartEvent", pollingTime);

            var msg = "Audience, vote for an event!";

            _MessageFeedManager.AddMessageToFeed(msg, MessageFeedManager.MessageType.generic);
        }
Exemplo n.º 4
0
 void OnReceivedPollList(PollChoices pollChoices)
 {
     if (!_GameIsAboutToEnd)
     {
         var pollManager = Instantiate(_PollPanelPrefab, _Canvas.transform).GetComponent <PollPanelManager>();
         pollManager.PollChoices       = pollChoices;
         pollManager.WasChoosingASpell = IsChoosingASpell;
     }
 }
Exemplo n.º 5
0
Arquivo: Poll.cs Projeto: smnsht/polls
        public PollChoices ToPollChoices(long choiceId, long pollId, long ordinal)
        {
            PollChoices entity = new PollChoices()
            {
                Id      = choiceId,
                PollId  = pollId,
                Choice  = this.Choice,
                Ordinal = ordinal
            };

            if (HasImage() && this.Image.ImageId > 0)
            {
                // set relation
                entity.ImageId = this.Image.ImageId;
            }

            return(entity);
        }
Exemplo n.º 6
0
        private void OnReceiveEventVotes(PollChoices pollChoices)
        {
            var voteA = pollChoices.events[0];
            var voteB = pollChoices.events[1];

            Debug.Log("Votes for A: " + voteA.votes);
            Debug.Log("Votes for B: " + voteB.votes);

            Event chosenEvent;

            if (voteA.votes == voteB.votes)
            {
                chosenEvent = Random.Range(0, 2) == 0 ? voteA : voteB;
            }
            else
            {
                chosenEvent = voteA.votes > voteB.votes ? voteA : voteB;
            }

            BroadcastPollResults(chosenEvent);
        }
 public void OnReceivePollResults(PollChoices pollChoices)
 {
     PollChoices = pollChoices;
     DisplayEventResults(pollChoices.events[0], _ImageA, _EventAResults);
     DisplayEventResults(pollChoices.events[1], _ImageB, _EventBResults);
 }
Exemplo n.º 8
0
        public ActionResult Create(NewPoll poll)
        {
            if (_isUserLoggedIn() == false)
            {
                return(_redirectToLogin());
            }

            if (ModelState.IsValid)
            {
                long imageId  = _db.NextPollImageId();
                long pollId   = _db.NextPollId();
                long choiceId = _db.NextPollChoiceId();

                using (var tran = _db.Database.BeginTransaction()) {
                    try{
                        if (poll.HasImage())
                        {
                            PollImages pi = poll.Image.ToPollImages(imageId, _userId);
                            _db.PollImages.Add(pi);
                            _db.SaveChanges();
                            poll.Image.ImageId = imageId;
                            imageId++;
                        }

                        Polls pollEntity = poll.ToPolls(pollId, _userId);
                        _db.Polls.Add(pollEntity);
                        _db.SaveChanges();

                        // polls choices - images
                        foreach (PollChoice cho in poll.Choices)
                        {
                            if (cho.HasImage())
                            {
                                PollImages img = cho.Image.ToPollImages(imageId, _userId);

                                // poll choices shell not use full image data - only the thumbs
                                // save space!
                                img.ImgData   = "";
                                img.ImgHeight = 0;
                                img.ImgWidth  = 0;

                                _db.PollImages.Add(img);
                                cho.Image.ImageId = imageId;
                                imageId++;
                            }
                        }

                        _db.SaveChanges();

                        long chordinal = 1;

                        // poll choices
                        foreach (PollChoice cho in poll.Choices)
                        {
                            PollChoices pocho = cho.ToPollChoices(choiceId, pollId, chordinal);
                            _db.PollChoices.Add(pocho);
                            choiceId++;
                            chordinal++;
                        }

                        _db.SaveChanges();

                        tran.Commit();
                    } catch (Exception ex) {
                        tran.Rollback();
                        return(Content(ex.Message));
                    }
                }

                return(Content("ok"));
            }

            return(Content(_buildErrorMessage()));
        }