public List<DataObjectSessionEvals> GetAllSessionEvals(string sortData) { SqlConnection conn = new SqlConnection(connectionString); conn.Open(); List<DataObjectSessionEvals> DataTemplateODSList = new List<DataObjectSessionEvals>(); SqlDataReader reader = null; string sqlSelectString = @"SELECT PKID, CreateDate, UpdateDate, CourseAsWhole, CourseContent, InstructorEff, InstructorAbilityExplain, InstructorEffective, InstructorKnowledge, QualityOfFacility, OverallCodeCamp, ContentLevel, Favorite, Improved, GeneralComments, DiscloseEval, sessionId, id FROM [dbo].[SessionEvals] ORDER BY sessionId"; SqlCommand cmd = new SqlCommand(sqlSelectString, conn); reader = cmd.ExecuteReader(); try { while (reader.Read()) { Guid pkid = reader.IsDBNull(0) ? Guid.NewGuid() : reader.GetGuid(0); DateTime createdate = reader.IsDBNull(1) ? DateTime.Now : reader.GetDateTime(1); DateTime updatedate = reader.IsDBNull(2) ? DateTime.Now : reader.GetDateTime(2); int courseaswhole = reader.IsDBNull(3) ? 0 : reader.GetInt32(3); int coursecontent = reader.IsDBNull(4) ? 0 : reader.GetInt32(4); int instructoreff = reader.IsDBNull(5) ? 0 : reader.GetInt32(5); int instructorabilityexplain = reader.IsDBNull(6) ? 0 : reader.GetInt32(6); int instructoreffective = reader.IsDBNull(7) ? 0 : reader.GetInt32(7); int instructorknowledge = reader.IsDBNull(8) ? 0 : reader.GetInt32(8); int qualityoffacility = reader.IsDBNull(9) ? 0 : reader.GetInt32(9); int overallcodecamp = reader.IsDBNull(10) ? 0 : reader.GetInt32(10); int contentlevel = reader.IsDBNull(11) ? 0 : reader.GetInt32(11); string favorite = reader.IsDBNull(12) ? "" : reader.GetString(12); string improved = reader.IsDBNull(13) ? "" : reader.GetString(13); string generalcomments = reader.IsDBNull(14) ? "" : reader.GetString(14); bool discloseeval = reader.IsDBNull(15) ? false : reader.GetBoolean(15); int sessionid = reader.IsDBNull(16) ? 0 : reader.GetInt32(16); int id = reader.IsDBNull(17) ? 0 : reader.GetInt32(17); DataObjectSessionEvals td = new DataObjectSessionEvals(pkid, createdate, updatedate, courseaswhole, coursecontent, instructoreff, instructorabilityexplain, instructoreffective, instructorknowledge, qualityoffacility, overallcodecamp, contentlevel, favorite, improved, generalcomments, discloseeval, sessionid, id); DataTemplateODSList.Add(td); } } finally { if (reader != null) reader.Close(); } conn.Close(); if (sortData == null) { sortData = "Id"; } if (sortData.Length == 0) { sortData = "Id"; } string sortDataBase = sortData; string descString = " DESC"; if (sortData.EndsWith(descString)) { sortDataBase = sortData.Substring(0, sortData.Length - descString.Length); } Comparison<DataObjectSessionEvals> comparison = null; switch (sortDataBase) { case "Createdate": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Createdate.CompareTo(rhs.Createdate); } ); break; case "Updatedate": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Updatedate.CompareTo(rhs.Updatedate); } ); break; case "Courseaswhole": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Courseaswhole.CompareTo(rhs.Courseaswhole); } ); break; case "Coursecontent": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Coursecontent.CompareTo(rhs.Coursecontent); } ); break; case "Instructoreff": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Instructoreff.CompareTo(rhs.Instructoreff); } ); break; case "Instructorabilityexplain": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Instructorabilityexplain.CompareTo(rhs.Instructorabilityexplain); } ); break; case "Instructoreffective": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Instructoreffective.CompareTo(rhs.Instructoreffective); } ); break; case "Instructorknowledge": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Instructorknowledge.CompareTo(rhs.Instructorknowledge); } ); break; case "Qualityoffacility": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Qualityoffacility.CompareTo(rhs.Qualityoffacility); } ); break; case "Overallcodecamp": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Overallcodecamp.CompareTo(rhs.Overallcodecamp); } ); break; case "Contentlevel": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Contentlevel.CompareTo(rhs.Contentlevel); } ); break; case "Favorite": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Favorite.CompareTo(rhs.Favorite); } ); break; case "Improved": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Improved.CompareTo(rhs.Improved); } ); break; case "Generalcomments": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Generalcomments.CompareTo(rhs.Generalcomments); } ); break; case "Discloseeval": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Discloseeval.CompareTo(rhs.Discloseeval); } ); break; case "Sessionid": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Sessionid.CompareTo(rhs.Sessionid); } ); break; case "Id": comparison = new Comparison<DataObjectSessionEvals>( delegate(DataObjectSessionEvals lhs, DataObjectSessionEvals rhs) { return lhs.Id.CompareTo(rhs.Id); } ); break; } if (comparison != null) { DataTemplateODSList.Sort(comparison); if (sortData.ToLower().EndsWith("desc")) { DataTemplateODSList.Reverse(); } } return DataTemplateODSList; }
public List<DataObjectSessionEvals> GetByUsernameSessionId(string username, int sessionId) { SqlConnection conn = new SqlConnection(connectionString); conn.Open(); List<DataObjectSessionEvals> DataTemplateODSList = new List<DataObjectSessionEvals>(); SqlDataReader reader = null; string sqlSelectString = @"SELECT PKID, CreateDate, UpdateDate, CourseAsWhole, CourseContent, InstructorEff, InstructorAbilityExplain, InstructorEffective, InstructorKnowledge, QualityOfFacility, OverallCodeCamp, ContentLevel, Favorite, Improved, GeneralComments, DiscloseEval, sessionId, id FROM [dbo].[SessionEvals] WHERE PKID = (SELECT PKID FROM Attendees WHERE Username = @username) AND (sessionId = @sessionId)"; SqlCommand cmd = new SqlCommand(sqlSelectString, conn); cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = username; ; cmd.Parameters.Add("@sessionId", SqlDbType.Int).Value = sessionId; reader = cmd.ExecuteReader(); try { while (reader.Read()) { Guid pkid = reader.IsDBNull(0) ? Guid.NewGuid() : reader.GetGuid(0); DateTime createdate = reader.IsDBNull(1) ? DateTime.Now : reader.GetDateTime(1); DateTime updatedate = reader.IsDBNull(2) ? DateTime.Now : reader.GetDateTime(2); int courseaswhole = reader.IsDBNull(3) ? 0 : reader.GetInt32(3); int coursecontent = reader.IsDBNull(4) ? 0 : reader.GetInt32(4); int instructoreff = reader.IsDBNull(5) ? 0 : reader.GetInt32(5); int instructorabilityexplain = reader.IsDBNull(6) ? 0 : reader.GetInt32(6); int instructoreffective = reader.IsDBNull(7) ? 0 : reader.GetInt32(7); int instructorknowledge = reader.IsDBNull(8) ? 0 : reader.GetInt32(8); int qualityoffacility = reader.IsDBNull(9) ? 0 : reader.GetInt32(9); int overallcodecamp = reader.IsDBNull(10) ? 0 : reader.GetInt32(10); int contentlevel = reader.IsDBNull(11) ? 0 : reader.GetInt32(11); string favorite = reader.IsDBNull(12) ? "" : reader.GetString(12); string improved = reader.IsDBNull(13) ? "" : reader.GetString(13); string generalcomments = reader.IsDBNull(14) ? "" : reader.GetString(14); bool discloseeval = reader.IsDBNull(15) ? false : reader.GetBoolean(15); int sessionid = reader.IsDBNull(16) ? 0 : reader.GetInt32(16); int id = reader.IsDBNull(17) ? 0 : reader.GetInt32(17); DataObjectSessionEvals td = new DataObjectSessionEvals(pkid, createdate, updatedate, courseaswhole, coursecontent, instructoreff, instructorabilityexplain, instructoreffective, instructorknowledge, qualityoffacility, overallcodecamp, contentlevel, favorite, improved, generalcomments, discloseeval, sessionid, id); DataTemplateODSList.Add(td); } } finally { if (reader != null) reader.Close(); } conn.Close(); return DataTemplateODSList; }