public IActionResult AddSurvey()
 {
     DailySurvey survey = new DailySurvey();
     DailySurveyViewModel model = new DailySurveyViewModel
     {
         SelectActivityLevelsList = ActivityLevels,
         SelectParkList = ParkSelectList(),
         SelectStatesList = States,
         Survey = survey
     };
     return View(model);
 }
        public void SaveSurvey(DailySurvey survey)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand(SQL_SaveNewSurvey, connection);
                cmd.Parameters.AddWithValue("@parkCode", survey.ParkCode);
                cmd.Parameters.AddWithValue("@emailAddress", survey.EmailAddress);
                cmd.Parameters.AddWithValue("@state", survey.State);
                cmd.Parameters.AddWithValue("@activityLevel", survey.ActivityLevel);

                cmd.ExecuteNonQuery();
            }
        }
Beispiel #3
0
        public IActionResult Survey(DailySurvey survey)
        {
            IActionResult result = null;

            if (!ModelState.IsValid)
            {
                result = View("Survey", survey);
            }
            else
            {
                _parkDao.AddSurvey(survey);
                result = RedirectToAction("FavoriteParks");
            }
            return(result);
        }
        /// <summary>
        /// Adds a new survey to the database.
        /// </summary>
        /// <param name="survey"></param>
        /// <returns>true if successful</returns>
        public bool AddSurvey(DailySurvey survey)
        {
            using (SqlConnection conn = new SqlConnection(_connString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(_addSurvey, conn);
                cmd.Parameters.AddWithValue("@parkCode", survey.ParkCode);
                cmd.Parameters.AddWithValue("@emailAddress", survey.EmailAddress);
                cmd.Parameters.AddWithValue("@state", survey.State);
                cmd.Parameters.AddWithValue("@activityLevel", survey.ActivityLevel);
                int rowsAffected = cmd.ExecuteNonQuery();

                return(rowsAffected > 0);
            }
        }
        public void SaveSurvey()
        {
            SurveySqlDal       dal     = new SurveySqlDal(connectionString);
            List <DailySurvey> surveys = dal.GetSurveyResults();

            surveyCount = surveys.Count();

            DailySurvey survey = new DailySurvey();

            survey.ParkCode      = "TESTI";
            survey.ActivityLevel = "sedentary";
            survey.EmailAddress  = "*****@*****.**";
            survey.State         = "HI";
            dal.SaveSurvey(survey);

            surveys = dal.GetSurveyResults();
            Assert.IsTrue(surveyCount + 1 == surveys.Count());
            Assert.IsTrue(surveys.Any(i => i.ParkCode == "TESTI"));
        }
        //public List<SelectListItem> GetParkSelectList()
        //{
        //    List<SelectListItem> parkList = new List<SelectListItem>();

        //    using (SqlConnection connection = new SqlConnection(connectionString))
        //    {
        //        connection.Open();


        //        SqlCommand command = new SqlCommand(SQL_GetParks, connection);
        //        var reader = command.ExecuteReader();
        //        while (reader.Read())
        //        {
        //            parkList.Add(MaptToRowPark(reader));
        //        }
        //    }
        //    return parkList;

        //}

        //private SelectListItem MaptToRowPark(SqlDataReader reader)
        //{
        //    return new SelectListItem()
        //    {
        //        Value = Convert.ToString(reader["parkCode"]),
        //        Text = Convert.ToString(reader["parkName"])
        //    };
        //}

        public List <DailySurvey> GetSurveyResults()
        {
            List <DailySurvey> results = new List <DailySurvey>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand    cmd    = new SqlCommand(SQL_GetSurveyResults, connection);
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    DailySurvey survey = new DailySurvey()
                    {
                        ParkCode   = Convert.ToString(reader["parkCode"]),
                        ParkName   = Convert.ToString(reader["parkName"]),
                        SurveyVote = Convert.ToInt32(reader["numberOfVotes"])
                    };
                    results.Add(survey);
                }
                return(results);
            }
        }
Beispiel #7
0
        public IActionResult Survey()
        {
            DailySurvey survey = new DailySurvey();

            return(View("Survey", survey));
        }