Exemplo n.º 1
0
        void rptPDetail_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item ||
                e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptPAnswer     = e.Item.FindControl("rptPAnswer") as Repeater;
                Repeater rptPUserAnswer = e.Item.FindControl("rptPUserAnswer") as Repeater;

                PredictionGameUserDetail pud = e.Item.DataItem as PredictionGameUserDetail;
                if (rptPAnswer != null && pud.Prediction != null)
                {
                    rptPAnswer.DataSource = pud.Prediction.PredictionAnswerses;
                    rptPAnswer.DataBind();
                }

                if (rptPUserAnswer != null && pud.Prediction != null)
                {
                    if (pud.Prediction.PredictionAnswerses != null)
                    {
                        foreach (PredictionAnswer ans in pud.Prediction.PredictionAnswerses)
                        {
                            if (ans.Id == pud.PredictionAnswer.Id)
                            {
                                ans.IsUserAnswer = true;
                                break;
                            }
                        }
                    }

                    rptPUserAnswer.DataSource     = pud.Prediction.PredictionAnswerses;
                    rptPUserAnswer.ItemDataBound += new RepeaterItemEventHandler(rptPUserAnswer_ItemDataBound);
                    rptPUserAnswer.DataBind();
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateAnswer(PredictionGameUser pgu)
        {
            PredictionGameUser pre = DomainManager.GetObject <PredictionGameUser>(PredictionGameUser.Id);

            if (pre != null)
            {
                foreach (PredictionGameUserDetail detail in pre.PredictionGameUserDetailses)
                {
                    if (detail.Prediction != null)
                    {
                        PredictionGameUserDetail tmp = pgu.PredictionGameUserDetailses.Cast <PredictionGameUserDetail>().Where(p => p.Prediction.Id == detail.Prediction.Id).FirstOrDefault();
                        if (tmp != null)
                        {
                            detail.PredictionAnswer = tmp.PredictionAnswer;
                        }
                    }
                }

                DomainManager.Update(pre);
            }
        }
Exemplo n.º 3
0
        private void SavePlayGame()
        {
            User curenttUser = Utils.GetCurrentUser();

            curenttUser = DomainManager.GetObject <User>(curenttUser.Id);

            string         cacheKey = hfCache.Value;
            PredictionGame pgame    = CMSCache.Get(cacheKey) as PredictionGame;

            if (curenttUser != null && pgame != null)
            {
                PredictionGameUser pgu = new PredictionGameUser();
                pgu.PlayDate       = DateTime.Now;
                pgu.PredictionGame = pgame;
                pgu.User           = curenttUser;

                TimeSpan?onsiteTime = null;
                if (Page.Session[TNHelper.PredictionStarTimeKey] is DateTime)
                {
                    onsiteTime = DateTime.Now - (DateTime)Page.Session[TNHelper.PredictionStarTimeKey];
                    pgu.Time   = onsiteTime.Value.Seconds;
                }

                if (pgame != null && pgame.Predictionses.Count > 0)
                {
                    foreach (Prediction p in pgame.Predictionses.Cast <Prediction>().ToList())
                    {
                        int        answerValue = GetUserAnswer(p);
                        Prediction prediction  = DomainManager.GetObject <Prediction>(p.Id);

                        if (answerValue >= 0)
                        {
                            PredictionGameUserDetail detail = new PredictionGameUserDetail();
                            detail.PredictionGameUser = pgu;
                            detail.Prediction         = prediction;
                            detail.PredictionAnswer   = DomainManager.GetObject <PredictionAnswer>(answerValue);
                            pgu.PredictionGameUserDetailses.Add(detail);
                        }
                    }
                }

                if (PredictionGameUser is PredictionGameUser)
                {
                    if (pgu.PredictionGame != null)
                    {
                        UpdateAnswer(pgu);
                        TNHelper.LogAction(LogType.PredictionLog, string.Format("Cập nhận đáp án cho bộ đề <b>{0}</b>", pgu.PredictionGame.PredictionGameName));
                    }
                }
                else
                {
                    if (pgu.PredictionGame != null)
                    {
                        DomainManager.Insert(pgu);
                        TNHelper.LogAction(LogType.PredictionLog, "Chơi game thử tài dự đoán");
                    }
                }

                // remove all relate cache
                Utils.ResetCurrentUser();
                CMSCache.RemoveByPattern(cacheKey);
            }
        }