Example #1
0
        public void AddVote(MembershipUser user , string comment, short weight)
        {
            Database db = DatabaseFactory.CreateDatabase("cnGrammit");

            if (comment.Length > 500)
                comment = comment.Substring(0, 496)+"...";

            object rtnVal = db.ExecuteScalar("dbo.usp_Z_Score_addVOTE", user.ProviderUserKey, this.ID, comment, weight);

            if (rtnVal != DBNull.Value)
            {
                int voteID = Convert.ToInt32(rtnVal);

                Vote vote = new Vote()
                {
                    ID = Convert.ToInt32(rtnVal),
                    Comment = comment,
                    UserId = user.ProviderUserKey.ToString(),
                    UserName = user.UserName.ToLower(),
                    Weight = weight,
                    Parent = this,
                    Dt = DateTime.UtcNow

                };

                this.Votes.Add(vote);
            }
        }
Example #2
0
        public void DeleteVote(Vote vote)
        {
            Database db = DatabaseFactory.CreateDatabase("cnGrammit");

            object rtnVal = db.ExecuteNonQuery( CommandType.Text, "DELETE from Z_SB_VOTE where ID = " + vote.ID.ToString());

            this.Votes.Remove(vote);
        }
        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;
        }