public ActionResult FillOut() { SurveyVM survey = new SurveyVM(); survey.Init(); return(View(survey)); }
public IList <SurveyVM> GetAllSurveys() { List <SurveyVM> surveyList = new List <SurveyVM>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); string sql = $"SELECT parkName, park.parkCode, COUNT(s.parkCode) as tally FROM park JOIN survey_result as s on s.parkCode = park.parkCode GROUP BY parkName, park.parkCode ORDER BY tally desc "; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); // Loop through each row while (reader.Read()) { SurveyVM vm = new SurveyVM(); vm.Tally = Convert.ToInt32(reader ["tally"]); vm.ParkName = Convert.ToString(reader["parkName"]); vm.ParkCode = Convert.ToString(reader["parkCode"]); surveyList.Add(vm); } } } catch (SqlException ex) { throw; } return(surveyList); }
// This method gets the surveys and shows the Name of the park along with the count of surveys rating it the favorite park by // the user. public IList <SurveyVM> GetAllSurveys() { IList <SurveyVM> output = new List <SurveyVM>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(@"SELECT park.parkName, park.parkCode, COUNT(*) AS surveyCount FROM park JOIN survey_result ON park.parkCode = survey_result.parkCode GROUP BY park.parkName, park.parkCode ORDER BY surveyCount DESC, park.parkName", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { SurveyVM model = ToPark(reader); output.Add(model); } } } catch (Exception ex) { throw; } return(output); }
public IActionResult Survey() { SurveyVM vm = new SurveyVM(); vm.Parks = nationalParkDAO.GetAllParks(); return(View(vm)); }
public ActionResult Create(SurveyVM suv, string employename) { IEnumerable <utilisateur> employesnum = us.GetEmployesByman(2); List <utilisateur> employesList = new List <utilisateur>(); foreach (var employe in employesnum) { employesList.Add(employe); } ViewData["employes"] = employesList; int empid = System.Convert.ToInt32(employename.Substring(0, 1)); try { if (questions.Count() == 0) { ModelState.AddModelError("", "Ajouter des questions !"); return(View()); } else { foreach (SurveyQuestion quest in questions) { quest.date = DateTime.Now; quest.employeId = empid; quest.managerId = 2; //surquestservice.Add(quest); } List <SurveyQuestion> questionlist = new List <SurveyQuestion>(); questionlist = questions; foreach (SurveyQuestion quest in questionlist) { quest.date = DateTime.Now; quest.employeId = empid; quest.managerId = 2; surquestservice.Add(quest); } Survey sv = new Survey() { date = DateTime.Now, duree = suv.duree, status = true, managerId = 2, employeId = empid }; surveyservice.Add(sv); surveyservice.Commit(); surquestservice.Commit(); questions.Clear(); return(RedirectToAction("Index")); } } catch (Exception e) { // Console.WriteLine(e.Message); return(View(e.Message)); } }
public IActionResult Index() { var survey = new SurveyVM(); var section = new SectionVM() { Label = "Section1" }; section.Controls.Add(new QuestionVM() { Label = "Question1" }); section.Controls.Add(new QuestionVM() { Label = "Question2" }); section.Controls.Add(new QuestionVM() { Label = "Question3" }); section.Controls.Add(new ButtonVM() { Label = "Button1" }); section.Controls.Add(new QuestionVM() { Label = "Question4" }); section.Controls.Add(new QuestionVM() { Label = "Question5" }); section.Controls.Add(new LabelVM() { Label = "I am a label!" }); survey.Controls.Add(section); var section2 = new SectionVM() { Label = "Section2" }; section2.Controls.Add(new QuestionVM() { Label = "Question6" }); section2.Controls.Add(new QuestionVM() { Label = "Question7" }); section2.Controls.Add(new QuestionVM() { Label = "Question8" }); section.Controls.Add(section2); return(View(survey)); }
public ActionResult Get(int cid, int sid) { SurveyRepo repo = new SurveyRepo(); SurveyVM surveyvm = repo.GetSurvey(sid); surveyvm.ClientID = cid; return(View(surveyvm)); }
public IActionResult TakeSurvey() { SurveyVM vm = new SurveyVM(); vm.parkNames = this.parkDao.GetParkSelections(); //set the list of Parks for selection (DAO, 'future-proof') vm.stateNames = this.StateSelection; //set the list of states for selection (hardcoded) vm.activityLevels = this.ActivityLevels; //set the list of activity levels for selection (hardcoded) return(View(vm)); }
// Used for the display part in the Favorite Parks View private SurveyVM ToPark(SqlDataReader reader) { SurveyVM model = new SurveyVM(); model.Park = new Park(); model.Park.ParkCode = Convert.ToString(reader["parkCode"]); model.Park.Name = Convert.ToString(reader["parkName"]); model.NumberOfSurveys = Convert.ToInt32(reader["surveyCount"]); return(model); }
public IActionResult Survey() { SurveyVM surveyVM = new SurveyVM(); IList <Park> parks = parkDAO.GetAllParks(); SelectList parkSelectList = new SelectList(parks, "ParkCode", "ParkName"); surveyVM.ParkDropdown = parkSelectList; ViewData["States"] = states; return(View(surveyVM)); }
public SurveyVM GetSurvey(int id) { SuperEarthComEntities1 ctx = new SuperEarthComEntities1(); SurveyVM vm = ctx.Surveys.Where(s => s.ID == id).Select(s => new SurveyVM { ID = s.ID, QuestionString = s.Questions }).SingleOrDefault(); vm.Questions = vm.QuestionString.Split('?').Where(q => !string.IsNullOrWhiteSpace(q)).ToList(); return(vm); }
public IActionResult Survey(SurveyVM surveyVM) { if (!ModelState.IsValid) { IList <Park> parks = parkDAO.GetAllParks(); SelectList parkSelectList = new SelectList(parks, "ParkCode", "ParkName"); surveyVM.ParkDropdown = parkSelectList; ViewData["States"] = states; return(View(surveyVM)); } surveyDAO.AddSurvey(surveyVM.Survey); return(RedirectToAction("FavoriteParks")); }
private bool SurveyMail(SurveyVM questions, SurveyVM answers) { string contactFromAddress = @System.Configuration.ConfigurationManager.AppSettings["ContactFromAddress"]; string contactBCCAddress = @System.Configuration.ConfigurationManager.AppSettings["ContactBCCAddress"]; string userName = @System.Configuration.ConfigurationManager.AppSettings["userName"]; string password = @System.Configuration.ConfigurationManager.AppSettings["password"]; string host = @System.Configuration.ConfigurationManager.AppSettings["host"]; int port = Convert.ToInt32(@System.Configuration.ConfigurationManager.AppSettings["port"]); UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current); var contactPage = helper.Content(1065); //get contactpage data string email = contactPage.contactUsDestinationAddress; //get destination address if (string.IsNullOrEmpty(email)) { return(false); } MailMessage mail = new MailMessage(); mail.To.Add(email); mail.From = new MailAddress(contactFromAddress, "Phigenics"); mail.Bcc.Add(contactBCCAddress); mail.Subject = "Survey submitted on " + DateTime.Now.ToString("d"); try { string templateBody = RenderViewToString(questions, answers); mail.Body = templateBody; mail.IsBodyHtml = true; var smtp = new SmtpClient(); smtp.Host = host; smtp.Port = port; smtp.UseDefaultCredentials = false; smtp.EnableSsl = true; var credential = new NetworkCredential { UserName = userName, Password = password }; smtp.Credentials = credential; smtp.Send(mail); } catch (Exception ex) { LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Mail Sending Error", ex); return(false); } return(true); }
// GET: SurveyClient/Details/5 public ActionResult Details(long empid, long manid, DateTime date) { Survey svy = surveyservice.Get(s => s.date == date && s.employeId == empid && s.managerId == manid); SurveyVM suvm = new SurveyVM { date = svy.date, duree = svy.duree, employe_id = svy.employeId, manager_id = svy.managerId, employee_Name = us.GetById((int)svy.employeId).nom + " " + us.GetById((int)svy.employeId).prenom, status = "Underway" }; ViewData["questions"] = svy.SurveyQuestions.ToList(); return(View(suvm)); }
public ActionResult Submit(SurveyVM survey) { //LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Post action invoked."); SurveyVM questions = new SurveyVM(); questions.Init(); if (ModelState.IsValid) { if (SurveyMail(questions, survey)) { //LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Email sent successfully."); bool success = survey.CollectAnswers(questions); if (success) { return(View("Thankyou", survey)); } } } return(View(questions)); }
public void TestGetAllSurveys() { // Arrange SurveyMockDAO surveyDAO = new SurveyMockDAO(); ParkMockDAO parkDAO = new ParkMockDAO(); SurveyController controller = new SurveyController(surveyDAO, parkDAO); // Act SurveyVM vm = new SurveyVM(); IActionResult result = controller.FavoriteParks(); ViewResult vr = result as ViewResult; IList <SurveyPost> surveys = surveyDAO.GetAllSurveys(); surveys = vr.Model as IList <SurveyPost>; // Assert Assert.IsNotNull(vr, "Index did not return a ViewResult"); Assert.AreEqual(4, surveys.Count); Assert.IsInstanceOfType(vr.Model, typeof(IList <SurveyPost>)); }
public ActionResult Survey(SurveyVM model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Hata Oluştu."); return(RedirectToAction("Survey", "Issue", model)); } try { var surveyRepo = _surveyRepo; var survey = surveyRepo.GetById(model.SurveyId); if (survey == null) { return(RedirectToAction("Index", "Home")); } Mapper.Map <SurveyVM, Survey>(model, survey); //survey.Pricing = model.Pricing; //survey.Satisfaction = model.Satisfaction; //survey.Solving = model.Solving; //survey.Speed = model.Speed; //survey.TechPoint = model.TechPoint; //survey.Suggestions = model.Suggestions; survey.IsDone = true; surveyRepo.Update(survey); TempData["Message"] = "Anket tamamlandı."; return(RedirectToAction("UserProfile", "Account")); } catch (Exception ex) { var errorVM = new ErrorVM() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "Survey", ControllerName = "Issue", ErrorCode = "500" }; TempData["ErrorMessage"] = JsonConvert.SerializeObject(errorVM); return(RedirectToAction("Error500", "Home")); } }
public static string RenderViewToString(SurveyVM questions, SurveyVM answers) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("<html><head><title>{0} Submitted</title></head><body><table border='0' cellpadding='10' cellspacing='10' width='100%'>", questions.SurveyTitle); sb.AppendFormat("<tr height='20'><td width='20%' height='20' style='font-size:14px; margin-top:10px;'>{0}</td></td><td width='30%' height='20' style='font-size:14px;'><strong>{1}</strong></td></tr>", "Name:", answers.ContactInfo.FullName); sb.AppendFormat("<tr height='20'><td width='20%' height='20' style='font-size:14px; margin-top:10px;'>{0}</td></td><td width='30%' height='20' style='font-size:14px;'><strong>{1}</strong></td></tr>", "Company:", answers.ContactInfo.Company); sb.AppendFormat("<tr height='20'><td width='20%' height='20' style='font-size:14px; margin-top:10px;'>{0}</td></td><td width='30%' height='20' style='font-size:14px;'><strong>{1}</strong></td></tr>", "Email:", answers.ContactInfo.Email); sb.Append("</table><br></br><br></br>"); int i = 0; sb.Append("<table border='0' cellpadding='10' cellspacing='10' width='100%'>"); sb.Append("<tr height='20'><td width='70%' height='20' style='font-size:14px; margin-top:10px;'><strong>Questions</strong></td><td width='10%' height='20' style='font-size:14px;'></td><td width='30%' height='20' style='font-size:12px; text-align:center; margin-top:10px;'><strong>Answer</strong></td></tr>"); foreach (Subject subject in questions.Subjects) { foreach (Question question in subject.Questions) { Answer answer = answers.Answers[i++]; sb.AppendFormat("<tr height='20'><td width='70%' height='20' style='font-size:14px; margin-top:10px;'>{0}</td><td width='10%' height='20' style='font-size:14px;'></td><td width='30%' height='20' style='font-size:12px; text-align:center; margin-top:10px;'><strong>{1}</strong></td></tr>", question.QuestionText, question.PossibleAnswers[(int)answer.SelectedAnswer - 1].AnswerText); } } sb.AppendFormat("</table></body></html>"); return(sb.ToString()); }
public IActionResult Survey(SurveyVM completedSurvey) { surveyDAO.SaveSurvey(completedSurvey.Survey); return(RedirectToAction("FavoriteParks")); }
public IActionResult Index(SurveyVM survey) { var id = survey.Id; return(View(survey)); }
public IActionResult TakeSurvey(SurveyVM vm) { this.SurveyDAO.SaveSurvey(vm.survey); return(RedirectToAction("Index")); }