public ActionResult Save(EmployeeChecklistViewModel model) { var request = new SaveEmployeeChecklistRequest { EmployeeChecklistId = model.EmployeeChecklistId, Answers = GetListOfAnswers( model) }; _employeeChecklistService.Save(request); return RedirectToAction("Index", new { employeeChecklistId = model.EmployeeChecklistId, saved = true }); }
public EmployeeChecklistViewModel GetViewModel() { var employeeChecklistViewModel = new EmployeeChecklistViewModel(); var employeeChecklist = _employeeChecklistService.GetById(_employeeChecklistId); employeeChecklistViewModel.EmployeeChecklistId = _employeeChecklistId; employeeChecklistViewModel.CompletedOnEmployeesBehalf = _completedOnEmployeesBehalf; employeeChecklistViewModel.ChecklistTitle = employeeChecklist.Checklist.Title; employeeChecklistViewModel.ChecklistDescription = new HtmlString(employeeChecklist.Checklist.Description); employeeChecklistViewModel.FriendlyReference = employeeChecklist.FriendlyReference; employeeChecklistViewModel.IsCompleted = employeeChecklist.CompletedDate.HasValue; employeeChecklistViewModel.Sections = new List<SectionViewModel>(); foreach (var section in employeeChecklist.Checklist.Sections.OrderBy(s => s.ListOrder)) { var sectionViewModel = new SectionViewModel(); sectionViewModel.Title = section.Title; sectionViewModel.Questions = new List<QuestionViewModel>(); foreach(var question in section.Questions.OrderBy(q => q.ListOrder)) { var questionViewModel = new QuestionViewModel(); questionViewModel.Id = question.Id; questionViewModel.ListOrder = question.ListOrder; questionViewModel.Text = question.Text; questionViewModel.QuestionType = question.QuestionType; questionViewModel.ListOrder = question.ListOrder; questionViewModel.Answer = GetAnswerForQuestion(question.Id, employeeChecklist.Answers); sectionViewModel.Questions.Add(questionViewModel); } employeeChecklistViewModel.Sections.Add(sectionViewModel); } employeeChecklistViewModel.IsCompleted = employeeChecklist.CompletedDate != null; return employeeChecklistViewModel; }
public void Given_i_have_answered_all_question_When_I_click_on_complete_Then_sned_complete_checklist_command() { // Given var questions = new List<QuestionViewModel>() { new QuestionViewModel() { Id = 1, QuestionType = QuestionType.YesNo, Answer = new AnswerViewModel()} }; var model = new EmployeeChecklistViewModel() { EmployeeChecklistId = Guid.NewGuid(), Sections = new List<SectionViewModel>() { new SectionViewModel() { Questions = questions } } }; CompleteEmployeeChecklistRequest passedCompleteEmployeeChecklistRequest = null; _employeeChecklistService .Setup(x => x.Complete(It.IsAny<CompleteEmployeeChecklistRequest>())) .Callback<CompleteEmployeeChecklistRequest>(z => passedCompleteEmployeeChecklistRequest = z); _employeeChecklistService .Setup(x => x.ValidateComplete(It.IsAny<CompleteEmployeeChecklistRequest>())) .Returns(new ValidationMessageCollection()); _target = GetTarget(); // When _target.Complete(model, new FormCollection()); // Then _bus.Verify(x => x.Send(It.Is<CompleteEmployeeChecklist>(y => y.EmployeeChecklistId == model.EmployeeChecklistId))); }
public void Given_i_have_answered_all_question_When_I_click_on_complete_Then_checklist_service_save_is_called() { // Given var questions = new List<QuestionViewModel>() { new QuestionViewModel() { Id = 1, QuestionType = QuestionType.YesNo, Answer = new AnswerViewModel() } }; var model = new EmployeeChecklistViewModel() { EmployeeChecklistId = Guid.NewGuid(), Sections = new List<SectionViewModel>() { new SectionViewModel() { Questions = questions } } }; _target = GetTarget(); // When _target.Complete(model, null); // Then _employeeChecklistService.Verify(x => x.Save(It.IsAny<SaveEmployeeChecklistRequest>())); }
public void Given_the_EmployeeChecklist_has_already_been_completed_When_I_try_to_complete_it_again_Then_complete_is_not_called() { // Given var questions = new List<QuestionViewModel>() { new QuestionViewModel() { Id = 1, QuestionType = QuestionType.YesNo, Answer = new AnswerViewModel()} }; var model = new EmployeeChecklistViewModel() { EmployeeChecklistId = Guid.NewGuid(), Sections = new List<SectionViewModel>() { new SectionViewModel() { Questions = questions } } }; CompleteEmployeeChecklistRequest passedCompleteEmployeeChecklistRequest = null; _employeeChecklistService .Setup(x => x.Complete(It.IsAny<CompleteEmployeeChecklistRequest>())) .Callback<CompleteEmployeeChecklistRequest>(z => passedCompleteEmployeeChecklistRequest = z); _employeeChecklistService .Setup(x => x.ValidateComplete(It.IsAny<CompleteEmployeeChecklistRequest>())) .Returns(new ValidationMessageCollection { new ValidationMessage(MessageType.Error, "This checklist has already been completed once and cannot be resubmitted.") }); _target = GetTarget(); // When var result = _target.Complete(model, new FormCollection()) as ViewResult; // Then var errors = result.ViewData.ModelState.Values.ToList(); _employeeChecklistService.Verify(x => x.Complete(It.IsAny<CompleteEmployeeChecklistRequest>()), Times.Never()); Assert.That(errors.Count, Is.EqualTo(1)); Assert.That(errors[0].Errors[0].ErrorMessage, Is.EqualTo("This checklist has already been completed once and cannot be resubmitted.")); }
private IList<SubmitAnswerRequest> GetListOfAnswers(EmployeeChecklistViewModel model) { return model.Sections.SelectMany(x => x.Questions) .Select(a => new SubmitAnswerRequest { AdditionalInfo = a.Answer.AdditionalInfo, BooleanResponse = a.Answer.BooleanResponse, QuestionId = a.Id }).ToList(); }
public ActionResult Complete(EmployeeChecklistViewModel model, FormCollection formCollection) { var request = new CompleteEmployeeChecklistRequest { EmployeeChecklistId = model.EmployeeChecklistId, Answers = GetListOfAnswers(model) }; var authenticationTicket = GetAuthenticationTicket(); //todo: why isn't it binding to model.CompletedOnEmployeesBehalf ??? if (Convert.ToBoolean(formCollection["CompletedOnEmployeesBehalf"]) && authenticationTicket != null) { request.CompletedOnEmployeesBehalfBy = new Guid(authenticationTicket.Name); } var validationMessages = _employeeChecklistService.ValidateComplete(request); if(validationMessages.Any()) { validationMessages.ForEach(message => ModelState.AddModelError("", message.Text)); return View("Index", model); } var completeCommandMessage = CreateCompleteEmployeeChecklistCommand(request); _bus.Send(completeCommandMessage); return RedirectToAction("Complete"); }