public List <SurveyResultsViewModel> GetTopSurveyResults() { List <SurveyResultsViewModel> parks = new List <SurveyResultsViewModel>(); string getParksSql = "SELECT COUNT(park.parkCode) AS numberOfVotes, park.parkCode, park.parkName, park.parkDescription FROM park JOIN survey_result ON park.parkCode = survey_result.parkCode GROUP BY park.parkName, park.parkDescription, park.parkCode ORDER BY numberOfVotes DESC, parkName, park.parkCode; "; using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(getParksSql, conn); var reader = cmd.ExecuteReader(); while (reader.Read()) { SurveyResultsViewModel park = new SurveyResultsViewModel(); park.ParkCode = Convert.ToString(reader["parkCode"]); park.Name = Convert.ToString(reader["parkName"]); park.Description = Convert.ToString(reader["parkDescription"]); park.NumOfVotes = Convert.ToInt32(reader["numberOfVotes"]); parks.Add(park); } } return(parks); }
public List <SurveyResultsViewModel> GetSurveyResults() { List <SurveyResultsViewModel> output = new List <SurveyResultsViewModel>(); //Create a SqlConnection to our database using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string getSurveySQLString = "select Count(survey_result.parkCode)as survey_count," + " park.parkName, park.parkCode " + "from survey_result " + "join park on survey_result.parkCode = park.parkCode " + "group by parkName, park.parkCode order by survey_count desc, parkName asc"; SqlCommand cmd = new SqlCommand(getSurveySQLString, connection); // Execute the query to the database SqlDataReader reader = cmd.ExecuteReader(); // The results come back as a SqlDataReader. Loop through each of the rows // and add to the output list while (reader.Read()) { SurveyResultsViewModel survey = new SurveyResultsViewModel(); survey.ParkName = Convert.ToString(reader["parkName"]); survey.ParkCode = Convert.ToString(reader["parkCode"]); survey.NumberOfSurvey = Convert.ToInt32(reader["survey_count"]); output.Add(survey); } } return(output); }
public async Task <IActionResult> SurveyResults() { var surveyResultsViewModel = new SurveyResultsViewModel { AllSurveyNames = await GetAllSurveyNames() }; return(View(surveyResultsViewModel)); }
public IActionResult Results() { Dictionary <string, int> surveysAndTheirCounts = surveyDAL.GetFavoriteParkBySurveyCount(); SurveyResultsViewModel srvm = new SurveyResultsViewModel() { Results = surveysAndTheirCounts, Parks = parkDAL.GetAllParks() }; return(View(srvm)); }
public ActionResult SurveyResults(int?id) { if (id == null) { return(HttpNotFound()); } var model = new SurveyResultsViewModel(); model.BeerType = db.BeerType.Where(b => b.BeerTypeId == id).FirstOrDefault(); model.Beers = db.Beer.Where(b => b.BeerTypeId == id).ToList(); return(View(model)); }
private List <SurveyResultsViewModel> BuildSurveyResults() { Dictionary <string, int> results = SurveyDAO.GetSurveyResults(); List <SurveyResultsViewModel> vmList = new List <SurveyResultsViewModel>(); foreach (KeyValuePair <string, int> kvp in results) { SurveyResultsViewModel vm = new SurveyResultsViewModel(); vm.ParkCode = kvp.Key; vm.NumVotes = kvp.Value; Park park = ParksDAO.GetParkByCode(vm.ParkCode); vm.ParkName = park.ParkName; vm.ParkLocation = park.State; vm.ParkClimate = park.Climate; vmList.Add(vm); } return(vmList); }
public ActionResult SurveyResults() { if (Session["AccountType"] != null && Session["LoggedIn"] != null) { if (Session["AccountType"].ToString() == "Manager") { SurveyResultsViewModel Model = new SurveyResultsViewModel(); Model.Surveys = ISurveyRepository.GetAllSurveys(); return(View("~/Views/Account/AccountViews/ManagerAccountOptions/SurveyResults.cshtml", Model)); } else { return(RedirectToAction("Account", "Account")); } } else { return(RedirectToAction("Account", "Account")); } }