Exemplo n.º 1
0
    private void BindData()
    {
        var _VoteQuestion = new VoteQuestion();

        rptList.DataSource = _VoteQuestion.GetList(AppUtils.Request("id"));
        rptList.DataBind();
    }
Exemplo n.º 2
0
        public VoteListPage(int argc)
        {
            InitializeComponent();

            ARGC = argc;
            Console.WriteLine(ARGC);
            var VoteQuestionQuery = App.database.GetVoteQuestions(1);

            Console.WriteLine("Questions Read, Nr: " + VoteQuestionQuery.Count());
            var VoteQuestionList = new List <VoteQuestion>();

            TGR         = new TapGestureRecognizer();
            TGR.Tapped += (s, e) => {
                IsEnabled = false;
                LoadVoteQuestion(s, e);
                IsEnabled = true;
            };



            foreach (VoteQuestionTable VQ in VoteQuestionQuery)
            {
                var VoteQ = new VoteQuestion(VQ);
                VoteQuestionList.Add(VoteQ);
                Console.WriteLine("Question Nr: " + VoteQ.VQ.Question);
                VotesGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });
                VotesGrid.RowSpacing = 5;
                VotesGrid.Children.Add(VoteQ.Box, 0, 3, Rownr, Rownr + 1);
                VotesGrid.Children.Add(VoteQ.Label, 0, 3, Rownr, Rownr + 1);
                Rownr++;
            }
        }
        public static VoteQuestion GetVoteQuestionBySlug(this AppDbContext context, string slug)
        {
            VoteQuestion voteQuestion =
                context.VoteQuestions.Include(x => x.Options).FirstOrDefault(x => x.Slug == slug);

            return(voteQuestion);
        }
Exemplo n.º 4
0
    public void Test_41247396()
    {
        Mapper.Initialize(config => {
            config.CreateMap <VoteAnswerOption, VoteAnswerOptionViewModel>().ReverseMap();
            config.CreateMap <VoteQuestion, CreateVoteQuestionViewModel>()
            .ForMember(dest => dest.PossibleAnswers,
                       opts => opts.MapFrom(src => src.VoteAnswerOptions));
            config.CreateMap <CreateVoteQuestionViewModel, VoteQuestion>()
            .ForMember(dest => dest.VoteAnswerOptions,
                       opts => opts.MapFrom(src => src.PossibleAnswers));
        });
        var voteQuestion = new VoteQuestion {
            VoteAnswerOptions = new List <VoteAnswerOption> {
                new VoteAnswerOption {
                    Answer = "Correct"
                }
            }
        };
        var newQuestion = Mapper.Map <VoteQuestion, CreateVoteQuestionViewModel>(voteQuestion);

        newQuestion.PossibleAnswers.Count.Should().Be(1);
        newQuestion.PossibleAnswers.Single().Answer.Should().Be("Correct");
        var vm = new CreateVoteQuestionViewModel {
            PossibleAnswers = new List <VoteAnswerOptionViewModel> {
                new VoteAnswerOptionViewModel {
                    Answer = "Spot on"
                }
            }
        };
        var q = Mapper.Map <CreateVoteQuestionViewModel, VoteQuestion>(vm);

        q.VoteAnswerOptions.Count.Should().Be(1);
        q.VoteAnswerOptions.Single().Answer.Should().Be("Spot on");
    }
        public void VoteOnQuestion(VoteQuestion v)
        {
            Question q = _ctx.Questions.FirstOrDefault(x => x.Id == v.QuestionId);

            q.Popularity += v.Value;
            _ctx.Questions.Update(q);
            _ctx.SaveChanges();
        }
        public static void UpdateVoteQuestion(this AppDbContext context, ViewModels.VoteQuestion voteQuestion)
        {
            VoteQuestion _voteQuestion = context.VoteQuestions.FirstOrDefault(x => x.Slug == voteQuestion.slug);

            _voteQuestion.Question = voteQuestion.question;
            _voteQuestion.Title    = voteQuestion.title;
            context.VoteQuestions.Update(_voteQuestion);
            context.SaveChanges();
        }
Exemplo n.º 7
0
        public static void VoteQuestionNew()
        {
            Guid         subId = SessionHelper.GetSession(SessionKey.SubDomain) == string.Empty ? Guid.Empty : new Guid(SessionHelper.GetSession(SessionKey.SubDomain));
            VoteQuestion item  = new VoteQuestion();

            item.Id             = Guid.NewGuid();
            item.SubDomainId    = subId;
            PSCDialog.DataShare = new VoteQuestionArgs(item, false);
        }
        /// <summary>
        /// Update region
        /// </summary>
        /// <param name="context"></param>
        /// <param name="regionInfo"></param>
        public static void UpdateSeedVoteQuestionInfo(this AppDbContext context, ViewModels.VoteQuestion voteQuestionInfo)
        {
            VoteQuestion voteQuestion = context.GetVoteQuestionBySlug(voteQuestionInfo.slug);

            if (voteQuestion == null)
            {
                context.AddInitialVoteQuestion(voteQuestionInfo);
            }
            else
            {
                voteQuestion.Question = voteQuestionInfo.question;
                voteQuestion.Title    = voteQuestionInfo.title;
                // update the options.
                if (voteQuestion.Options != null)
                {
                    // first pass to add new items.
                    foreach (var option in voteQuestionInfo.options)
                    {
                        VoteOption voteOption = voteQuestion.Options.FirstOrDefault(x => x != null && x.Option.Equals(option.option));
                        if (voteOption == null)
                        {
                            voteQuestion.Options.Add(option.ToModel());
                        }
                        else
                        {
                            voteOption.DisplayOrder = option.displayOrder;
                        }
                    }
                    List <VoteOption> itemsToRemove = new List <VoteOption>();
                    // second pass to identify items that are no longer present.
                    foreach (var option in voteQuestion.Options)
                    {
                        if (option != null)
                        {
                            if (voteQuestionInfo.options.FirstOrDefault(x => x != null && x.option.Equals(option.Option)) == null)
                            {
                                itemsToRemove.Add(option);
                            }
                        }
                    }
                    // third pass to remove the items.
                    foreach (var option in itemsToRemove)
                    {
                        voteQuestion.Options.Remove(option);
                    }
                }
                context.VoteQuestions.Update(voteQuestion);
                context.SaveChanges();
            }
        }
        public IActionResult VoteQuestion([FromForm] VoteQuestion r)
        {
            _service.VoteOnQuestion(r);
            var origQ        = _service.GetQuestionById(r.QuestionId);
            var qResponses   = _service.GetRelatedResponses(origQ.Id);
            var viewQuestion = new QuestionForView
            {
                Id         = origQ.Id,
                Title      = origQ.Title,
                Body       = origQ.Body,
                UserId     = origQ.UserId,
                Popularity = origQ.Popularity,
                Responses  = qResponses
            };

            return(View("Details", viewQuestion));
        }
        /// <summary>
        /// Adds a jurisdiction to the system, only if it does not exist.
        /// </summary>
        private static void AddInitialVoteQuestion(this AppDbContext context, ViewModels.VoteQuestion initialVoteQuestion)
        {
            VoteQuestion voteQuestion = context.GetVoteQuestionBySlug(initialVoteQuestion.slug);

            if (voteQuestion != null)
            {
                return;
            }

            voteQuestion = new VoteQuestion
                           (
                initialVoteQuestion.question,
                initialVoteQuestion.slug,
                initialVoteQuestion.title,
                initialVoteQuestion.options
                           );

            context.AddVoteQuestion(voteQuestion);
        }
Exemplo n.º 11
0
    protected void btAdd_Click(object sender, EventArgs e)
    {
        var _VoteQuestion = new VoteQuestion();
        int voteID        = AppUtils.Request("id");

        if (txtAddName.Text.Trim().Length > 0 && txtAddCount.Text.Trim().Length > 0)
        {
            _VoteQuestion.VoteID = voteID;
            _VoteQuestion.Name   = txtAddName.Text.Trim();
            _VoteQuestion.Count  = Convert.ToInt32(txtAddCount.Text);
            _VoteQuestion.Add();
        }

        for (int i = 0; i < rptList.Items.Count; i++)
        {
            CheckBox cbxCheck       = (CheckBox)rptList.Items[i].FindControl("cbxCheck");
            TextBox  txtUpdateName  = (TextBox)rptList.Items[i].FindControl("txtName");
            TextBox  txtUpdateCount = (TextBox)rptList.Items[i].FindControl("txtCount");
            Label    lblQuestionID  = (Label)rptList.Items[i].FindControl("lblQuestionID");

            _VoteQuestion.QuestionID = Convert.ToInt32(lblQuestionID.Text);

            if (cbxCheck.Checked)
            {
                _VoteQuestion.Delete();
            }
            else
            {
                _VoteQuestion       = _VoteQuestion.Get();
                _VoteQuestion.Name  = txtUpdateName.Text.Trim();
                _VoteQuestion.Count = Convert.ToInt32(txtUpdateCount.Text);
                _VoteQuestion.Update();
            }
        }

        BindData();
        txtAddName.Text  = "";
        txtAddCount.Text = "0";
    }
Exemplo n.º 12
0
        private void CheckAnswer()
        {
            VoteQuestion selectQuestion = questions[selectQuestionId];

            supportRateHumanOld = supportRateHuman;
            supportRateOrcOld   = supportRateOrc;
            supportRateElfOld   = supportRateElf;
            supportRateDwalfOld = supportRateDwalf;
            supportRateHuman    = GetNewSupportRate(supportRateHuman, MathTool.GetRandom(selectQuestion.EffHumanMin, selectQuestion.EffHumanMax));
            supportRateOrc      = GetNewSupportRate(supportRateOrc, MathTool.GetRandom(selectQuestion.EffOrcMin, selectQuestion.EffOrcMax));
            supportRateElf      = GetNewSupportRate(supportRateElf, MathTool.GetRandom(selectQuestion.EffElfMin, selectQuestion.EffElfMax));
            supportRateDwalf    = GetNewSupportRate(supportRateDwalf, MathTool.GetRandom(selectQuestion.EffDwalfMin, selectQuestion.EffDwalfMax));

            supportRateTotal  = countHuman * supportRateHuman + supportRateOrc * countOrc + supportRateElf * countElf + supportRateDwalf * countDwalf;
            supportRateTotal /= (countHuman + countOrc + countElf + countDwalf);

            round++;
            if (round >= 10)
            {
                score = (int)(supportRateTotal * 100);
                EndGame();
            }
        }
        /// <summary>
        /// Returns a specific VoteQuestion
        /// </summary>
        /// <param name="name">The name of the VoteQuestion</param>
        /// <returns>The VoteQuestion, or null if it does not exist.</returns>
        public static VoteQuestion GetVoteQuestionById(this AppDbContext context, string id)
        {
            VoteQuestion voteQuestion = context.VoteQuestions.Include(x => x.Options).FirstOrDefault(x => x.Id == new Guid(id));

            return(voteQuestion);
        }
 public static void AddVoteQuestion(this AppDbContext context, VoteQuestion voteQuestion)
 {
     // create a new jurisdiction.
     context.VoteQuestions.Add(voteQuestion);
     context.SaveChanges();
 }
Exemplo n.º 15
0
        public static void VoteQuestionAdd()
        {
            VoteQuestion question = ((VoteQuestionArgs)PSCDialog.DataShare).VoteQuestion;

            VoteQuestionList.AddDB(question);
        }
Exemplo n.º 16
0
        private void LoadData()
        {
            string subName = Request.Url.Host.Replace(ConfigurationManager.AppSettings["DomainName"], "");

            if (subName.Length > 0)
            {
                subName = subName.Substring(0, subName.Length - 1);
            }
            SubDomain subDomain = subName == string.Empty ? SubDomain.GetSubByName("HomePage") : SubDomain.GetSubByName(subName);

            if (subDomain == null)
            {
                voteQuestion = VoteQuestion.GetVoteQuestionActive();
            }
            else
            {
                voteQuestion = VoteQuestion.GetVoteQuestionBySubDomainActive(subDomain.Id);
            }

            VoteQuestionName         = voteQuestion.Name;
            ListVoteAnswer           = VoteAnswerCollection.GetVoteAnswerCollectionByVoteQuestion(voteQuestion);
            rblVoteAnswer.DataSource = ListVoteAnswer;
            rblVoteAnswer.DataBind();
            rblVoteAnswer.SelectedIndex = 0;
            TotalVoteNumber             = ListVoteAnswer.Sum(item => item.Number);
            /**/
            lb_TongSoPhieu.Text      = "Tổng số phiếu: " + TotalVoteNumber;
            lb_XemKetQua_CauHoi.Text = voteQuestion.Name;
            gv_KetQua.DataSource     = ListVoteAnswer;
            gv_KetQua.DataBind();
        }

        protected override void DeleteData()
        {
            //using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PSCPortalConnectionString"].ConnectionString))
            //{
            //    SqlCommand com = new SqlCommand();
            //    com.Connection = con;
            //    con.Open();
            //    com.CommandType = System.Data.CommandType.Text;
            //    com.Parameters.AddWithValue("@dataId", Portlet.PortletInstance.Id);
            //    com.CommandText = "Delete Vote Where DataId=@dataId";
            //}
        }

        protected string ComputePercent(int SoPhieu)
        {
            if (TotalVoteNumber == 0)
            {
                return("00.00 %");
            }
            float percent = (float)SoPhieu / TotalVoteNumber * 100;

            return(percent.ToString("00.00") + " %");
        }

        protected void ibt_Chon_Click(object sender, ImageClickEventArgs e)
        {
            if (rblVoteAnswer.SelectedIndex != -1)
            {
                if (Request.Cookies["Vote"] != null)
                {
                    return;
                }
                HttpCookie httpCookie = new HttpCookie("Vote", "");
                httpCookie.Expires = DateTime.Now.AddSeconds(60);
                Response.Cookies.Add(httpCookie);
                Guid       selectedVote = new Guid((string)rblVoteAnswer.SelectedValue);
                VoteAnswer voteAnswer   = ListVoteAnswer.Where(item => ((VoteAnswer)item).Id == selectedVote).Single();
                voteAnswer.Number = voteAnswer.Number + 1;
                voteAnswer.Update();
                TotalVoteNumber = TotalVoteNumber + 1;
                /**/
                lb_TongSoPhieu.Text  = "Tổng số phiếu: " + TotalVoteNumber;
                gv_KetQua.DataSource = ListVoteAnswer;
                gv_KetQua.DataBind();
                Response.Redirect(Request.Url.ToString());
            }