public SurveySummary ConvertSurvey(Survey survey) { SurveySummary ss = new SurveySummary(); ss.Survey = survey; ss.EntryCount = _repository.GetEntryCount(survey.ID); ss.AdminComments = _repository.GetApprovals(survey.ID); return ss; }
public void AdminController_Preview_Action_Should_Fetch_A_Survey_From_Repo() { // arrange var repositoryStub = MockRepository.GenerateStub<IRepository>(); var sut = new AdminController(repositoryStub); const int surveyId = 1; var survey = new Survey(); repositoryStub .Stub(x => x.GetSurvey(surveyId)) .Return(survey); // act var sur = repositoryStub.GetSurvey(surveyId); var actual = sut.Preview(surveyId); // assert var viewResult = (PartialViewResult)actual; Assert.AreEqual(survey, viewResult.ViewData.Model); Assert.AreEqual("selected", sut.TempData["Selected_Admin"], "Selected tab was incorrect."); }
public SurveySummary ConvertFullSurvey(Survey survey) { SurveySummary ss = new SurveySummary(); ss.Survey = survey; ss.Questions = new List<QuestionSummary>(); ss.EntryCount = _repository.GetEntryCount(survey.ID); ss.AdminComments = _repository.GetApprovals(survey.ID); List<Question> questions = _repository.GetQuestions(survey.ID); foreach (Question question in questions) { QuestionSummary qs = new QuestionSummary(); qs.Question = question; qs.Answers = new List<AnswerSummary>(); List<Answer> answers = _repository.GetAnswers(question.ID); foreach (var answer in answers) { AnswerSummary ans = new AnswerSummary(); ans.Answer = answer; ans.ResponseCount = _repository.GetResponseCount(answer.ID); int totalcount = ss.EntryCount; ans.ResponsePercentage = 0; if (ans.ResponseCount > 0) { ans.ResponsePercentage = Convert.ToInt32(ans.ResponseCount * 100 / totalcount); } qs.Answers.Add(ans); } ss.Questions.Add(qs); } return ss; }
/// <summary> /// Deprecated Method for adding a new object to the Surveys EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSurveys(Survey survey) { base.AddObject("Surveys", survey); }
/// <summary> /// Create a new Survey object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="createdBy">Initial value of the CreatedBy property.</param> /// <param name="createdOn">Initial value of the CreatedOn property.</param> /// <param name="live">Initial value of the Live property.</param> /// <param name="approved">Initial value of the Approved property.</param> public static Survey CreateSurvey(global::System.Int32 id, global::System.String title, global::System.String createdBy, global::System.DateTime createdOn, global::System.Int32 live, global::System.Int32 approved) { Survey survey = new Survey(); survey.ID = id; survey.Title = title; survey.CreatedBy = createdBy; survey.CreatedOn = createdOn; survey.Live = live; survey.Approved = approved; return survey; }
public ActionResult Index(Survey model, IEnumerable<HttpPostedFileBase> file) { TempData["Selected_New"] = "selected"; // This uploads the image and adds the URL string physicalPath = HttpContext.Server.MapPath("/") + "UploadImages" + "\\"; for (int i = 0; i < Request.Files.Count; i++) { Request.Files[0].SaveAs(physicalPath + System.IO.Path.GetFileName(Request.Files[i].FileName)); model.Image = System.IO.Path.GetFileName(Request.Files[i].FileName); } // To make sure the model binding doesn't change hidden values, override values model.CreatedBy = User.Identity.Name; model.CreatedOn = DateTime.Now; model.Live = 0; model.Approved = 0; model.ApprovedBy = null; model.ApprovedOn = null; model.Deleted = 0; // Send the survey object to the repository to create a new entry. Returns the survey ID int survey = _repository.CreateSurvey(model); // if the survey has been created and returns a correct ID, display the next stage if (survey != 0) return RedirectToAction("AddQuestion", new { surveyId = survey }); // Display an error ViewData["Message"] = "There has been an error. Please try again."; return View(model); }
public SurveySummary ConvertFullSurvey(Survey survey) { SurveySummary ss = new SurveySummary(); ss.Survey = survey; ss.Questions = new List<QuestionSummary>(); ss.EntryCount = _repository.GetEntryCount(survey.ID); ss.AdminComments = _repository.GetApprovals(survey.ID); List<Question> questions = _repository.GetQuestions(survey.ID); foreach (Question question in questions) { QuestionSummary qs = new QuestionSummary(); qs.Question = question; qs.Answers = new List<AnswerSummary>(); List<Answer> answers = _repository.GetAnswers(question.ID); foreach (var answer in answers) { AnswerSummary ans = new AnswerSummary(); ans.Answer = answer; qs.Answers.Add(ans); } ss.Questions.Add(qs); } return ss; }