public ForumSection(ForumSection sec) { SectionId = sec.SectionId; SectionTitle = sec.SectionTitle; ThreadCount = sec.ThreadCount; DateCreated = sec.DateCreated; DateModified = sec.DateModified; CreatorId = sec.CreatorId; CategoryId = sec.CategoryId; published = sec.published; DatePublished = sec.DatePublished; }
//parametrized constructor public ForumThread(string title, string body, string sec, int published, int creator) { //sectionid SectionId = ForumSection.GetSectionIdbyName(sec); ThreadTitle = title; ThreadBody = body; DateCreated = DateTime.Now; DateModified = DateTime.Now; Published = published; if (published == 1) { DatePublished = DateTime.Now; } CreatorId = creator; }
//populate sectionlist attribute from db public void GetPublishedSectionsFromDb() { SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["globaldb"].ConnectionString); string q1 = "SELECT * FROM f_section where Published=1 AND CategoryId=" + this.CategoryId; SqlCommand com1 = new SqlCommand(q1, con1); con1.Open(); SqlDataReader rdr = com1.ExecuteReader(); ForumSection sec; while (rdr.Read()) { sec = new ForumSection(); sec.SectionId = Convert.ToInt32(rdr["SectionId"]); sec.SectionTitle = rdr["SectionTitle"].ToString(); sec.ThreadCount = Convert.ToInt32(rdr["ThreadCount"]); if (!(rdr["DateCreated"] == DBNull.Value)) { sec.DateCreated = Convert.ToDateTime(rdr["DateCreated"]); } if (!(rdr["DateModified"] == DBNull.Value)) { sec.DateModified = Convert.ToDateTime(rdr["DateModified"]); } sec.CategoryId = this.CategoryId; sec.published = 1; if (!(rdr["DatePublished"] == DBNull.Value)) { sec.DatePublished = Convert.ToDateTime(rdr["DatePublished"]); } if (!(rdr["CreatorID"] == DBNull.Value)) { sec.CreatorId = Convert.ToInt32(rdr["CreatorID"]); } SectionList.Add(new ForumSection(sec)); } con1.Close(); }