public List <ParkSurveyCount> GetSurveyCountList() { List <ParkSurveyCount> surveyResults = new List <ParkSurveyCount>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GetAllSurveys, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ParkSurveyCount psc = new ParkSurveyCount(); psc.ParkCode = Convert.ToString(reader["parkCode"]); psc.ParkName = Convert.ToString(reader["parkName"]); psc.SurveyCount = Convert.ToInt32(reader["surveyCount"]); surveyResults.Add(psc); } } } catch (SqlException ex) { throw; } return(surveyResults); }
public ActionResult SurveyResult() { SurveyResultsModel surveyResult = new SurveyResultsModel(); surveyResult.ParkSurveyList = new List<ParkSurveyCount>(); surveyResult.Fahrenheit = CheckTemp(); using (var context = new ParkSystemDatabaseEntities()) { foreach(var park in context.survey_result) foreach (var survey in context.survey_result) { ParkSurveyCount count = new ParkSurveyCount{ park = survey.park, numberOfSurveys = survey.park.parkCode.Count() }; surveyResult.ParkSurveyList.Add(count); } } surveyResult.ParkSurveyList.OrderBy(model => model.numberOfSurveys); return View(surveyResult); }