private static AskAboutQuestion[] Fetch(int id, string name, string question) { List<AskAboutQuestion> lAskAboutQuestion = new List<AskAboutQuestion>(); using(SqlConnection conn = Config.DB.Open()) { SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchAskAboutQuestion", id, name); while(reader.Read()) { AskAboutQuestion aQuestion = new AskAboutQuestion(); aQuestion.id = (int)reader["Id"]; aQuestion.name = (string)reader["Name"]; aQuestion.question = (string)reader["QuestionDisplay"]; aQuestion.active = (bool)reader["Active"]; lAskAboutQuestion.Add(aQuestion); } } return lAskAboutQuestion.ToArray(); }
/// <summary> /// Creates the specified name. /// </summary> /// <param name="name">The name.</param> /// <param name="active">if set to <c>true</c> [active].</param> /// <returns></returns> public static AskAboutQuestion Create(string name,string question, bool active) { AskAboutQuestion newQuestion = new AskAboutQuestion(); newQuestion.id = -1; newQuestion.name = name; newQuestion.QuestionDisplay = question; newQuestion.active = active; return newQuestion; }
/// <summary> /// Fetches all. /// </summary> /// <returns></returns> public static AskAboutQuestion[] FetchAll() { string cacheKey = String.Format("AskAboutQuestion_FetchAll"); if(HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return HttpContext.Current.Cache[cacheKey] as AskAboutQuestion[]; } using(SqlConnection conn = Config.DB.Open()) { SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchAskAboutQuestions"); List<AskAboutQuestion> lQuestions = new List<AskAboutQuestion>(); while(reader.Read()) { AskAboutQuestion aQuestion = new AskAboutQuestion(); aQuestion.id = (int)reader["Id"]; aQuestion.name = (string)reader["Name"]; aQuestion.active = (bool)reader["Active"]; aQuestion.question = (string)reader["QuestionDisplay"]; lQuestions.Add(aQuestion); } AskAboutQuestion[] questions = lQuestions.ToArray(); if(HttpContext.Current != null) { //Global.AddCacheItem("AskAboutQuestions", cacheKey, questions); HttpContext.Current.Cache.Insert(cacheKey, questions, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null); } return questions; } }