public async Task SubmitConfirmedEmployerFeedback(SurveyModel surveyModel) { var employerFeedback = await _employerFeedbackRepository.GetEmployerFeedbackRecord(surveyModel.UserRef, surveyModel.AccountId, surveyModel.Ukprn); long feedbackId = 0; if (null == employerFeedback) { feedbackId = await _employerFeedbackRepository.UpsertIntoFeedback(surveyModel.UserRef, surveyModel.AccountId, surveyModel.Ukprn); } else { feedbackId = employerFeedback.FeedbackId; } if (feedbackId == default(long)) { throw new InvalidOperationException($"Unable to find or create feedback record"); } try { var providerAttributes = await ConvertSurveyToProviderAttributes(surveyModel); var feedbackSource = ProvideFeedback.Data.Enums.FeedbackSource.AdHoc; if (surveyModel.UniqueCode.HasValue) { feedbackSource = ProvideFeedback.Data.Enums.FeedbackSource.Email; } var employerFeedbackResultId = await _employerFeedbackRepository.CreateEmployerFeedbackResult( feedbackId, surveyModel.Rating.Value.GetDisplayName(), DateTime.UtcNow, feedbackSource, providerAttributes); if (null != surveyModel.UniqueCode && surveyModel.UniqueCode.HasValue) { // Email journey. Burn the survey code. await _employerFeedbackRepository.SetCodeBurntDate(surveyModel.UniqueCode.Value); } } catch (Exception ex) { _logger.LogError(ex, "Failed to submit feedback"); } }
public void AddQuestionCopiesCachedSurveyToTempDataWhenModelIsNotValid() { using (var controller = new SurveysController(null, null, null, null, null)) { controller.ModelState.AddModelError("error for test", "invalid model state"); var cachedSurvey = new SurveyModel(); controller.TempData[SurveysController.CachedSurvey] = cachedSurvey; var result = controller.AddQuestion(null) as ViewResult; var cachedSurveyReturnedInTempData = result.TempData[SurveysController.CachedSurvey] as SurveyModel; Assert.AreSame(cachedSurvey, cachedSurveyReturnedInTempData); } }
public async Task <IActionResult> QuestionOne(Guid uniqueCode, SurveyModel surveyModel) { if (!IsProviderAttributesValid(surveyModel)) { return(View(surveyModel)); } var sessionAnswer = await _sessionService.Get <SurveyModel>(uniqueCode.ToString()); SetStengths(sessionAnswer, surveyModel.Attributes.Where(x => x.Good)); await _sessionService.Set(uniqueCode.ToString(), sessionAnswer); return(await HandleRedirect(RouteNames.QuestionTwo_Get)); }
/// <summary> /// Searches the survey response for a well-known answer, e.g., initials or date of birth. /// </summary> /// <param name="response">The survey response.</param> /// <param name="survey">The survey.</param> /// <param name="question">The well-known question type.</param> /// <returns> /// The specified valid of the well-known answer, or <code>null</code> if not found. /// </returns> public static string GetWellKnownAnswer(this SurveyResponseModel response, SurveyModel survey, WellKnownQuestion question) { var nameQuestion = survey.Questions .FirstOrDefault(q => q.WellKnownQuestion == question); if (nameQuestion == null) { return(null); } return(response.QuestionResponses .FirstOrDefault(r => r.QuestionID == nameQuestion.QuestionID)? .AnswerChoiceResponses?.FirstOrDefault()? .AdditionalAnswerData); }
public ActionResult Survey(SurveyModel model) { if (Request.HttpMethod == "POST" && ModelState.IsValid) { ModelState.Clear(); var text = model.Name + " " + model.Email + " " + model.Author + " " + model.Title + " " + model.Readed + " " + model.TimesReaded + " " + model.Rating + " " + model.Publisher; var newMOdel = new SurveyModel() { Hidden = false, Result = text }; return(View(newMOdel)); } return(View(model)); }
public void NewWhenHttpVerbIsPostReturnsErrorInModelStateWhenCachedSurveyHasNoQuestions() { var cachedSurvey = new SurveyModel { Questions = new List <Question>() }; using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null)) { controller.TempData[SurveysController.CachedSurvey] = cachedSurvey; var result = controller.New(new SurveyModel()) as ViewResult; Assert.IsTrue(controller.ModelState.Keys.Contains("ContentModel.Questions")); } }
public void NewWhenHttpVerbIsPostSavesCachedSurveyInTempDataWhenModelStateIsNotValid() { var cachedSurvey = new SurveyModel(); using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null)) { controller.ModelState.AddModelError("error for test", "invalid model state"); controller.TempData[SurveysController.CachedSurvey] = cachedSurvey; var result = controller.New(new SurveyModel()) as ViewResult; var model = result.ViewData.Model as TenantPageViewData <Survey>; Assert.AreSame(cachedSurvey, controller.TempData[SurveysController.CachedSurvey]); } }
public void NewWhenHttpVerbIsPostReturnsTitleInTheModelWhenModelStateIsNotValid() { var survey = new SurveyModel(); using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null)) { controller.ModelState.AddModelError("error for test", "invalid model state"); controller.TempData[SurveysController.CachedSurvey] = new SurveyModel(); var result = controller.New(survey) as ViewResult; var model = result.ViewData.Model as TenantMasterPageViewData; Assert.AreSame("New Survey", model.Title); } }
public async Task <IActionResult> QuestionThree(Guid uniqueCode, SurveyModel surveyModel) { if (!ModelState.IsValid) { return(View(surveyModel)); } var idClaim = HttpContext.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier); var sessionAnswer = await _sessionService.Get <SurveyModel>(idClaim.Value); sessionAnswer.Rating = surveyModel.Rating; await _sessionService.Set(idClaim.Value, sessionAnswer); return(await HandleRedirect(RouteNames.ReviewAnswers_Get)); }
public void TestImportSurveyJSON() { using (PITCSurveyContext db = new PITCSurveyContext()) { ModelConverter mc = new ModelConverter(db); var js = new JavaScriptSerializer(); SurveyModel Model = js.Deserialize <SurveyModel>(File.ReadAllText(".\\Data\\PITYouthCountSurvey.json")); Survey Survey = mc.ConvertToEntity(Model); Console.WriteLine(); } }
/// <summary> /// Get user answers /// </summary> /// <param name="pacode"></param> /// <returns></returns> public SurveyModel getUserAnswers(string pacode) { SurveyModel model = new SurveyModel(); using (LBCData context = new LBCData(ConnectionHelper.getConnectionString())) { var survey = from r in context.LBC_REGISTRATION from s in context.LBC_SURVEY_TAKEN.Where(s => s.STARS_ID == r.PA_CODE).DefaultIfEmpty() where r.PA_CODE.Equals(pacode) select new SurveyModel(); model = survey.SingleOrDefault(); } return(model); }
public int AddSurvey([FromBody] SurveyModel survey) { Survey sur = new Survey { Title = survey.Title, Description = survey.Description, Code = GenerateCode(), OrganisationID = survey.OrganisationID, StartDate = CheckStartDate(survey.StartDate), EndDate = CheckEndDate(survey.EndDate) }; var surveyid = _sr.Add(sur); return(surveyid.ID); }
public async Task <IActionResult> QuestionTwo(Guid uniqueCode, SurveyModel surveyModel) { if (!IsProviderAttributesValid(surveyModel)) { return(View(surveyModel)); } var idClaim = HttpContext.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier); var sessionAnswer = await _sessionService.Get <SurveyModel>(idClaim.Value); SetWeaknesses(sessionAnswer, surveyModel.Attributes.Where(x => x.Bad)); await _sessionService.Set(idClaim.Value, sessionAnswer); return(await HandleRedirect(RouteNames.QuestionThree_Get)); }
public CommonResult ValidationSurveyDate(SurveyModel surveyModel) { if (surveyModel.Start_date > surveyModel.End_date) { return(new CommonResult(CommonResultState.Warning, Properties.Resources.NotValidData1)); } else if (surveyModel.Start_date.Date < DateTime.Now.Date) { return(new CommonResult(CommonResultState.Warning, Properties.Resources.NotValidData2)); } else { return(new CommonResult(CommonResultState.OK, Properties.Resources.CorrectDataValidation)); } }
public async Task <ActionResult> Edit(SurveyModel model) { var strUrl = APIProvider.APIGenerator(ControllerName, APIConstant.ACTION_UPDATE); var result = await APIProvider.Authorize_DynamicTransaction <SurveyModel, int>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CORE, ARS.Edit); if (result > 0) { TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(ValueConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.SUCCESS)); } else { TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ISUSED, ApplicationGenerator.GeneralActionMessage(ValueConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.ISUSED)); } return(RedirectToAction("Index")); }
public ConfirmationControllerTests() { _cachedSurveyModel = _fixture.Create <SurveyModel>(); var sessionServiceMock = new Mock <ISessionService>(); var loggerMock = new Mock <ILogger <ConfirmationController> >(); var optionsMock = new Mock <IOptionsMonitor <MaPageConfiguration> >(); var linkGeneratorMock = new Mock <ILinkGenerator>(); var maPageConfiguration = new MaPageConfiguration { Routes = new MaRoutes { Accounts = new Dictionary <string, string>() } }; maPageConfiguration.Routes.Accounts.Add("AccountsHome", "http://AnAccountsLink/{0}"); optionsMock.Setup(s => s.CurrentValue).Returns(maPageConfiguration); linkGeneratorMock.Setup(s => s.AccountsLink(It.IsAny <string>())).Returns <string>(x => x); var config = new ProvideFeedbackEmployerWebConfiguration() { ExternalLinks = _externalLinks }; var urlBuilder = new UrlBuilder(Mock.Of <ILogger <UrlBuilder> >(), optionsMock.Object, linkGeneratorMock.Object); sessionServiceMock .Setup(mock => mock.Get <SurveyModel>(It.IsAny <string>())) .Returns(Task.FromResult(_cachedSurveyModel)); _controller = new ConfirmationController( sessionServiceMock.Object, config, urlBuilder, loggerMock.Object); var context = new DefaultHttpContext() { User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "TestUserIdValue"), })) }; _controller.ControllerContext = new ControllerContext { HttpContext = context }; }
public void SavePostTest() { SurveyModel model = new SurveyModel() { FavoritePark = "Everglades National Park", Email = "*****@*****.**", Residence = "OH", ActivityLevel = "Low" }; SurveySqlDAL dal = new SurveySqlDAL(connectionString); bool result = dal.SaveNewPost(model); Assert.AreEqual(true, result); }
public static SurveyContract GetContract(this SurveyModel contract) { return(new SurveyContract { IdSurvey = contract.IdSurvey, Name = contract.Name, Description = contract.Description, EndDateUTC = contract.EndDateUTC, Answers = contract.Answers.Select(s => new AnswerContract { IdAnswer = s.IdAnswer, IdSurvey = s.IdSurvey, Text = s.Text }).ToArray() }); }
public IActionResult AddSurvey(SurveyModel surveyModel) { if (surveyModel != null && surveyModel.SurveyTitle != null && (surveyModel.SurveyChoiceModel.Count != 1 && surveyModel.SurveyChoiceModel[0] != null)) { } else { return(Redirect("/Survey")); } surveyModel.ApplicationUserId = _userManager.GetUserId(HttpContext.User); _applicationDbContext.Surveys.Add(surveyModel); _applicationDbContext.SaveChanges(); return(Redirect("/Survey")); }
public async Task <IActionResult> CreateSurvey([FromBody] SurveyModel survey) { if (!ModelState.IsValid) { return(BadRequest("Niepoprawne dane")); } var result = await surveyService.AddSurvey(survey); if (result.StateMessage == CommonResultState.OK) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public void NewWhenHttpVerbIsPostReturnsNewSurveyAsTitleInTheModelWhenCachedSurveyHasNoQuestions() { var cachedSurvey = new SurveyModel { Questions = new List <Question>() }; using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null)) { controller.TempData[SurveysController.CachedSurvey] = cachedSurvey; var result = controller.New(new SurveyModel()) as ViewResult; var model = result.ViewData.Model as TenantMasterPageViewData; Assert.AreSame("New Survey", model.Title); } }
public IActionResult NewSurvey(SurveyModel surveyModel) { if (!ModelState.IsValid) { Dictionary <string, string> parks = parkSqlDAL.GetParkNames(); SurveyModel surveyModelReplacement = new SurveyModel(); surveyModelReplacement.ParksByName(parks); return(View("Index", surveyModelReplacement)); } surveySqlDAL.SaveSurvey(surveyModel); return(RedirectToAction("SurveyResults")); }
public async void Question_3_Should_Handle_Return_Url() { // Arrange var surveyModel = new SurveyModel { Rating = ProviderRating.Excellent }; _controller.TempData.Add("ReturnUrl", RouteNames.ReviewAnswers_Get); // Act var result = await _controller.QuestionThree(_uniqueCode, surveyModel); // Assert Assert.IsAssignableFrom <RedirectToRouteResult>(result); Assert.Equal(RouteNames.ReviewAnswers_Get, (result as RedirectToRouteResult).RouteName); }
public void NewWhenHttpVerbIsPostSavesCachedSurveyInTempDataWhenCachedSurveyHasNoQuestions() { var cachedSurvey = new SurveyModel { Questions = new List <Question>() }; using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null)) { controller.TempData[SurveysController.CachedSurvey] = cachedSurvey; var result = controller.New(new SurveyModel()) as ViewResult; var model = result.ViewData.Model as TenantPageViewData <Survey>; Assert.AreSame(cachedSurvey, controller.TempData[SurveysController.CachedSurvey]); } }
public async void Question_3_When_Answers_Submitted_Should_Update_Session_And_Redirect() { // Arrange var surveyModel = new SurveyModel { Rating = ProviderRating.Excellent }; // Act var result = await _controller.QuestionThree(_uniqueCode, surveyModel); // Assert _sessionServiceMock.Verify(mock => mock.Set(It.IsAny <string>(), It.IsAny <object>()), Times.Once); var redirectResult = Assert.IsAssignableFrom <RedirectToRouteResult>(result); Assert.Equal(RouteNames.ReviewAnswers_Get, redirectResult.RouteName); }
public void NewQuestionCopiesSurveyTitleToCachedSurveyThatIsReturnedInViewData() { var survey = new SurveyModel { Title = "title" }; using (var controller = new SurveysController(null, null, null, null, null)) { controller.TempData[SurveysController.CachedSurvey] = new SurveyModel(); var result = controller.NewQuestion(survey) as ViewResult; var cachedSurvey = result.TempData[SurveysController.CachedSurvey] as SurveyModel; Assert.AreSame(survey.Title, cachedSurvey.Title); } }
public ConfirmationControllerTests() { _cachedSurveyModel = Fixture.Create <SurveyModel>(); _sessionServiceMock = new Mock <ISessionService>(); _providerFeedbackRepoMock = new Mock <IGetProviderFeedback>(); _loggerMock = new Mock <ILogger <ConfirmationController> >(); _externalLinksOptions = Options.Create(_externalLinks); _sessionServiceMock .Setup(mock => mock.Get <SurveyModel>(It.IsAny <string>())) .Returns(Task.FromResult(_cachedSurveyModel)); _controller = new ConfirmationController( _sessionServiceMock.Object, _providerFeedbackRepoMock.Object, _externalLinksOptions, _loggerMock.Object); }
public void PostOneSurvey() { NationalParkSqlDal nationalParkDAL = new NationalParkSqlDal(connectionString); SurveyModel surveyTest = new SurveyModel { Email = "*****@*****.**", ActivityLevel = "sedentary", ParkName = "Grand Teton National Park", StateOfResidence = "Ohio" }; bool testPass = nationalParkDAL.AddSurvey(surveyTest); Assert.AreEqual(true, testPass); }
public async Task SubmitConfirmedEmployerFeedback(SurveyModel surveyModel, Guid uniqueCode) { var employerFeedback = ConvertToEmployerFeedback(surveyModel); Document doc = null; try { doc = await _employerFeedbackRepository.CreateItemAsync(employerFeedback); await _employerEmailDetailRepository.SetCodeBurntDate(uniqueCode); } catch (Exception ex) { _logger.LogError(ex, "Failed to submit feedback"); } }
public ActionResult New() { var temporarySurveyModel = GetTemporarySurveyModel(); if (temporarySurveyModel == null) { temporarySurveyModel = new SurveyModel(); // First time to the page } var model = this.CreatePageViewData(temporarySurveyModel); model.Title = "New Survey"; SaveTemporarySurveyModel(temporarySurveyModel); return(this.View(model)); }