public QuestionaryTimelineStepViewModel(QuestionaryActionSettings settings, ViewModelResolver resolver) : base(settings) { _id = settings.Id; var questions = settings.Questions? .Where(q => resolver.CanCreate(q)) .Select(q => { string question = q.Question.Lines != null && q.Question.Lines.Any() ? String.Join(Environment.NewLine, q.Question.Lines) : String.Empty; return(new QuestionViewModel(question, q.Id, (IQuestionAnswerViewModel)resolver.Create(q), q.IsRequired, q.HelpText)); }); Title = settings.Title?.Trim() ?? String.Empty; Questionary = new QuestionaryViewModel(questions); HasQuestions = Questionary.Questions.Any(); Cursor = Cursors.Arrow; }
public ActionResult Index(QuestionaryViewModel questionary) { questionary.Name = questionary.Name.Trim(); if (string.IsNullOrEmpty(questionary.Name)) { ModelState.AddModelError("Name", "Please enter your name."); } else if (questionary.Name.Length < 3 || questionary.Name.Length > 30) { ModelState.AddModelError("Name", "Name must be 3-30 characters in length."); } else if (!Regex.Match(questionary.Name, "^[A-Za-zА-Яа-яЁёІі\\s]+$").Success) { ModelState.AddModelError("Name", "Invalid name."); } if (questionary.Rate == 0) { ModelState.AddModelError("Rate", "Please choose rating."); } if (ModelState.IsValid) { questionaryService.AddItem(new QuestionaryDto() { Name = questionary.Name, Rate = questionary.Rate, Recommend = questionary.Recommend }); ViewBag.SiteRate = questionaryService.GetRate(); return(View("QuestionaryResult", questionary)); } else { return(View(questionary)); } }
public async Task <IActionResult> Post([FromBody] QuestionaryViewModel questionary) { // Save to the Database try { var newQuestionary = Mapper.Map <Questionary>(questionary); _repository.AddQuestionary(newQuestionary); if (await _repository.SaveChangesAsync()) { return(Created($"api/questionaries/{questionary.QuestName}", Mapper.Map <QuestionaryViewModel>(questionary))); } else { _logger.LogWarning("Could not save questionary to the database"); } } catch (Exception ex) { _logger.LogError($"Threw exception while saving questionary: {ex}"); } return(BadRequest("Failed to save the questionary")); }
public IActionResult Questionary(QuestionaryViewModel model) { if (!ModelState.IsValid) { return(View(model)); } //var user = _userRepository.Get(model.Id); var questionary = _mapper.Map <Questionary>(model); /*= new Profile() * { * Name = model.Name, * SurName = model.SurName, * BirthDate = model.BirthDate, * Sex = model.Sex, * PhoneNumber = model.PhoneNumber, * PostAddress = model.PostAddress, * IdentificationPassport = model.IdentificationPassport * };*/ var user = _userService.GetCurrent(); //userprofile.User = user; //userprofile.UserRef = user.Id; //_userRepository.Save(userprofile); questionary.User = user; //questionary.UserRef = user.Id; _questionaryRepository.Save(questionary); return(RedirectToAction("QuestionaryDataOutput")); }
public QuestionaryViewModel UpdateQuestionaryViewModel(QuestionaryViewModel questionaryViewModel) { questionaryViewModel.Questionaries = EFQuestionary.Questionaries.OrderByDescending(q => q.QuestionaryID).ToPagedList(questionaryViewModel.PageIndex, 10); questionaryViewModel.Questions = EFQuestionary.Questions; questionaryViewModel.Selects = EFQuestionary.Selects; questionaryViewModel.FillOuts = EFQuestionary.FillOuts; return(questionaryViewModel); }
public ActionResult QuestionaryManage(int PageIndex = 1) { DealViewBag("QuestionaryManage"); QuestionaryViewModel = GetQuestionaryViewModel(PageIndex); if (Request.IsAjaxRequest()) { return(PartialView("_Questionary", QuestionaryViewModel)); } return(View(QuestionaryViewModel)); }
public QuestionaryViewModel GetQuestionaryViewModel(int PageIndex) { QuestionaryViewModel = new QuestionaryViewModel { Questionaries = EFQuestionary.Questionaries.OrderByDescending(q => q.QuestionaryID).ToPagedList(PageIndex, 10), Questions = EFQuestionary.Questions, Selects = EFQuestionary.Selects, FillOuts = EFQuestionary.FillOuts.Where(f => f.GameID == GameID), PageIndex = PageIndex, }; return(QuestionaryViewModel); }
public ActionResult DelQuestionary(string QuestionaryID) { if (!string.IsNullOrEmpty(QuestionaryID)) { if (EFQuestionary.DelQuestionary(QuestionaryID)) { QuestionaryViewModel = GetQuestionaryViewModel(1); return(PartialView("_Questionary", QuestionaryViewModel)); } } return(View(false)); }
public ActionResult ShowQuestionaryResult(string QuestionaryID) { if (!string.IsNullOrEmpty(QuestionaryID)) { Questionary questionary = EFQuestionary.Questionaries.Where(q => q.QuestionaryID == QuestionaryID).FirstOrDefault(); if (questionary != null) { QuestionaryViewModel questionaryViewModel = new QuestionaryViewModel { Questionary = questionary, Questions = EFQuestionary.Questions.Where(q => q.QuestionaryID == questionary.QuestionaryID).OrderBy(q => q.QuestionID), Selects = EFQuestionary.Selects, FillOuts = EFQuestionary.FillOuts.Where(f => f.QuestionaryID == questionary.QuestionaryID).OrderBy(s => s.GameID), GameMembers = EFGameMember.gameMembers, }; return(View(questionaryViewModel)); } } return(View(false)); }
public ActionResult AddQuestionary(Questionary questionary, QuestionaryViewModel questionaryViewModel) { if (ModelState.IsValid) { if (questionary.StartTime > questionary.EndTime) { return(View(false)); } if (questionary.EndTime < DateTime.Now) { return(View(false)); } if (EFQuestionary.AddQuestionary(questionary)) { questionaryViewModel = UpdateQuestionaryViewModel(questionaryViewModel); return(PartialView("_Questionary", questionaryViewModel)); } } return(View(false)); }
public void GetProfileViewModel_0(long id) { var userprofile = new SpaceWeb.EfStuff.Model.Questionary() { Id = id, Name = "A", SurName = "B" }; var prof = new QuestionaryViewModel() { Id = id }; _mockRepository.Setup(x => x.Get(id)).Returns(userprofile); _mockMapper.Setup(x => x.Map <QuestionaryViewModel>(userprofile)).Returns(prof); var profile = _bankPresentation.GetProfileViewModel(id); _mockMapper.Verify(x => x.Map <QuestionaryViewModel>(userprofile), Times.AtLeastOnce); Assert.AreEqual(profile.Name, null); }