/// <summary> /// Retrieves list of ChapterContent objects from SqlCommand, after database query /// number of rows retrieved and returned depends upon the rows field value /// </summary> /// <param name="cmd">The command object to use for query</param> /// <param name="rows">Number of rows to process</param> /// <returns>A list of ChapterContent objects</returns> private ChapterContentList GetList(SqlCommand cmd, long rows) { // Select multiple records SqlDataReader reader; long result = SelectRecords(cmd, out reader); //ChapterContent list ChapterContentList list = new ChapterContentList(); using ( reader ) { // Read rows until end of result or number of rows specified is reached while (reader.Read() && rows-- != 0) { ChapterContent chapterContentObject = new ChapterContent(); FillObject(chapterContentObject, reader); list.Add(chapterContentObject); } // Close the reader in order to receive output parameters // Output parameters are not available until reader is closed. reader.Close(); } return(list); }
/// <summary> /// Retrieves all ChapterContent objects by PageRequest /// </summary> /// <returns>A list of ChapterContent objects</returns> public ChapterContentList GetPaged(PagedRequest request) { using (SqlCommand cmd = GetSPCommand(GETPAGEDCHAPTERCONTENT)) { AddParameter(cmd, pInt32Out("TotalRows")); AddParameter(cmd, pInt32("PageIndex", request.PageIndex)); AddParameter(cmd, pInt32("RowPerPage", request.RowPerPage)); AddParameter(cmd, pNVarChar("WhereClause", 4000, request.WhereClause)); AddParameter(cmd, pNVarChar("SortColumn", 128, request.SortColumn)); AddParameter(cmd, pNVarChar("SortOrder", 4, request.SortOrder)); ChapterContentList _ChapterContentList = GetList(cmd, ALL_AVAILABLE_RECORDS); request.TotalRows = Convert.ToInt32(GetOutParameter(cmd, "TotalRows")); return(_ChapterContentList); } }
/// <summary> /// Retrieve list of ChapterContent. /// </summary> /// <param name="fillChild"></param> /// <returns>List of ChapterContent</returns> public ChapterContentList GetAll(bool fillChild) { ChapterContentList chapterContentList = new ChapterContentList(); using (ChapterContentDataAccess data = new ChapterContentDataAccess(ClientContext)) { chapterContentList = data.GetAll(); } if (fillChild) { foreach (ChapterContent chapterContentObject in chapterContentList) { FillChapterContentWithChilds(chapterContentObject, fillChild); } } return(chapterContentList); }
public ActionResult ChapterContent(int chapterid) { List <ChapterContentList> chapterContentViewModel = new List <ChapterContentList>(); string constring = ConfigurationManager.ConnectionStrings["TutorialContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { SqlCommand command = new SqlCommand(); command.CommandText = "select * from Chapter where ChapterID=@ChapterID"; command.Connection = con; command.Parameters.AddWithValue("@ChapterID", chapterid); con.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader == null) { return(Json(null, JsonRequestBehavior.AllowGet)); } while (reader.Read()) { ChapterContentList c = new ChapterContentList(); { // c.TutorialID = (int)reader["TutorialID"]; // c.ChapterID = (int)reader["ChapterID"]; c.ChapterName = (string)reader["ChapterName"]; c.HierarchyLevel = (int)reader["HierarchyLevel"]; c.Discription = (string)reader["Discription"]; c.TypeOfFile = (int)reader["TypeOfFile"]; c.ContentOfFile = (string)reader["ContentOfFile"]; }; chapterContentViewModel.Add(c); } return(Json(chapterContentViewModel, JsonRequestBehavior.AllowGet)); } }