Ejemplo n.º 1
0
        public void AddScore(Score score)
        {
            Database db = DatabaseFactory.CreateDatabase("cnGrammit");

            score.ID = Convert.ToInt32(db.ExecuteScalar("dbo.usp_Z_Score_addScore", new Guid(score.UserId), this.ID, score.RatingRaw, score.Text, score.IsPro));

            List<Score> list = (score.IsPro) ? this.Pros : this.Cons;

            //remove placeholder
            if (list.Count == 1 && list[0].RatingRaw == 0)
                list.RemoveAt(0);

            list.Add(score);
        }
Ejemplo n.º 2
0
        private string AddScore(string username, string userPass, string gameName, string gamePass, int points)
        {
            User user = users.FirstOrDefault(u => u.Username == username && u.Password == userPass);
            Game game = games.FirstOrDefault(g => g.GameName == gameName && g.GamePassword == gamePass);
            if (user != null)
            {
                if (game != null)
                {
                    var score = new Score()
                    {
                        User = user,
                        Game = game,
                        Points = points
                    };

                    this.scores.Add(score);
                    return "Score added";
                }

                return "Cannot add score";
            }

            return "Cannot add score";
        }
        protected void grdPro_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                //e.Row.Cells[0].CssClass = "score";
                //e.Row.Cells[1].CssClass = "score";
                //if (sender == this.grdPro)
                //    e.Row.Cells[1].Text = board.ProTotal.ToString();
                //else
                //    e.Row.Cells[1].Text = board.ProTotal.ToString();
                //e.Row.Cells.RemoveAt(1);
            }
            else if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int scoreIdx = (sender == grdPro) ? 1 : 2;
                int textIdx  = (sender == grdPro) ? 2 : 1;

                //activates the #board td.score class
                e.Row.Cells[scoreIdx].CssClass = "sc";

                Score score = e.Row.DataItem as Score;

                bool alreadyVoted = (user == null) ? false : score.AlreadyVoted(user.ProviderUserKey.ToString());

                HtmlGenericControl btnUp   = e.Row.Cells[textIdx].FindControl("btnUp") as HtmlGenericControl;
                HtmlGenericControl btnDown = e.Row.Cells[textIdx].FindControl("btnDown") as HtmlGenericControl;
                HtmlGenericControl btnCom  = e.Row.Cells[textIdx].FindControl("btnCom") as HtmlGenericControl;


                //enable the delete button
                if (score.Votes != null && score.Votes.Count == 0)
                {
                    user = (user == null) ? Membership.GetUser() : user;
                    if (user != null && score.UserId == user.ProviderUserKey.ToString())
                    {
                        LinkButton deleteBtn = e.Row.Cells[textIdx].FindControl("btnDel") as LinkButton;
                        deleteBtn.CommandArgument = score.ID.ToString();
                        deleteBtn.EnableViewState = true;
                        deleteBtn.Visible         = true;
                        deleteBtn.Text            = "delete";
                        deleteBtn.CssClass        = "del";
                    }
                }

                string voteFunction = (user == null) ? "$find('mpbSignup').show();" :
                                      (score.RatingRaw == 0) ? "$find('mpeScore').show();" : ("showCom(event," + score.ID.ToString() + ", {0}, this);");

                if (alreadyVoted)
                {
                    //format whether comments can be added
                    btnUp.Attributes.Add("class", "up-ya");
                    btnDown.Attributes.Add("class", "down-ya");
                }
                else
                {
                    btnUp.Attributes.Add("onclick", string.Format(voteFunction, "1"));
                    btnDown.Attributes.Add("onclick", string.Format(voteFunction, "-1"));
                }
                btnCom.Attributes.Add("onclick", string.Format(voteFunction, "0"));

                //Panel comments = e.Row.Cells[0].FindControl("comments") as Panel;
                //for (int i = 0; i < score.Votes.Count; i++)
                //{
                //    Vote vote = score.Votes[i];
                //    HtmlGenericControl comment = new HtmlGenericControl("div");
                //    comment.Attributes.Add("class", "comment");

                //    if (vote.Comment == string.Empty)
                //        if (vote.Weight > 0)
                //            vote.Comment = "vote +1";
                //        else if (vote.Weight < 0)
                //            vote.Comment = "vote -1";

                //    comment.InnerText = vote.Comment;
                //    comments.Controls.Add(comment);

                //}
            }
        }
Ejemplo n.º 4
-1
        public static ScoreBored Load(string boredName)
        {
            ScoreBored frankenstein = null;

            Database db = DatabaseFactory.CreateDatabase("cnGrammit");

            //remove the "_" chars first
            using (IDataReader rdr = db.ExecuteReader("[usp_Z_Score_getBoard]", boredName))
            {
                if (rdr.Read())
                {
                    frankenstein = new ScoreBored()
                    {
                        ID = Convert.ToInt32(rdr["ID"]),
                        UserId = rdr["UserID"].ToString(),
                        UserName = rdr["UserName"].ToString(),
                        ConName = rdr["CON_NAME"].ToString(),
                        Cons = new List<Score>(),
                        Created = DateTime.Parse(rdr["DT_CREATED"].ToString()),
                        Description = rdr["DESCRIPTION"].ToString(),
                        Name = rdr["NAME"].ToString(),
                        ProName = rdr["PRO_NAME"].ToString(),
                        Pros = new List<Score>(),
                        Phrases = new Dictionary<short, string>(),
                        PhraseIs = Convert.ToBoolean(rdr["IS_PHRASE"])

                    };
                }
                else
                {
                    return null;
                }
                if (rdr.NextResult())
                {
                    while (rdr.Read()){
                        Score score = new Score(){
                             Created = DateTime.Parse(rdr["DT_CREATED"].ToString()),
                              RatingRaw = Convert.ToInt32(rdr["SCORE"]),
                               Text =  rdr["WORDS"].ToString(),
                                UserId = rdr["UserID"].ToString(),
                                ID = Convert.ToInt32(rdr["ID"]),
                                 Votes = new List<Vote>(Convert.ToInt32(rdr["VOTES"])),
                                  IsPro = Convert.ToBoolean(rdr["IS_PRO"])
                        };

                        if (score.IsPro)
                        {
                            frankenstein.Pros.Add(score);
                        }
                        else
                            frankenstein.Cons.Add(score);
                    }
                }

                if (rdr.NextResult())
                {
                    while (rdr.Read())
                    {
                        frankenstein.Phrases.Add(Convert.ToInt16(rdr["MARGIN"]), rdr["PHRASE"].ToString());
                    }
                }

                if (rdr.NextResult())
                {
                    while (rdr.Read())
                    {
                        Score parentScore = frankenstein.FindScore(Convert.ToBoolean(rdr["IS_PRO"]), Convert.ToInt32(rdr["SCORE_ID"]));

                        Vote vote = new Vote()
                        {
                            ID = Convert.ToInt32(rdr["ID"]),
                            Comment = rdr["COMMENT"].ToString(),
                            UserId = rdr["UserId"].ToString(),
                            UserName = rdr["UserName"].ToString(),
                            Weight = Convert.ToInt16(rdr["WEIGHT"]),
                            Dt = Convert.ToDateTime(rdr["DT_CREATED"]),
                            Parent = parentScore
                        };
                        parentScore.Votes.Add(vote);
                    }
                }
            }

            if (frankenstein.Pros.Count == 0)
            {
                frankenstein.Pros.Add(
                    new Score()
                    {
                        ID = 0,
                        RatingRaw = 0,
                         Text="Vote to add points"
                    });
            }
            if (frankenstein.Cons.Count == 0)
            {
                frankenstein.Cons.Add(
                    new Score()
                    {
                        ID = 0,
                        RatingRaw = 0,
                        Text = "Vote to add points"
                    });
            }

            return frankenstein;
        }
        protected void btnVote_Click(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                LoadBored();

                Score rating = new Score()
                {
                    Created = DateTime.UtcNow,
                    RatingRaw = int.Parse(Rating1.CurrentRating.ToString()),
                    Text = txtEntry.Text,
                    UserId = Membership.GetUser().ProviderUserKey.ToString(),
                     Votes = new List<Vote>(1),
                      IsPro = (sender == btnPro)

                };
                _board.AddScore(rating);

                BindAll();

                txtEntry.Text = string.Empty;

                upScore.Update();
                upBoards.Update();
                upComs.Update();
            }
            else
            {
                MPESignup.Show();
                Rating1.CurrentRating = 1;
            }
        }