private void AddRelevantDateToNewDate(DateInputViewModel model) { var command = model.Command; switch (command) { case KeyDatesStatusEnum.NotificationReceived: model.NewDate = model.NotificationReceivedDate; break; case KeyDatesStatusEnum.AssessmentCommenced: model.NewDate = model.CommencementDate; break; case KeyDatesStatusEnum.NotificationComplete: model.NewDate = model.NotificationCompleteDate; break; case KeyDatesStatusEnum.NotificationTransmitted: model.NewDate = model.NotificationTransmittedDate; break; case KeyDatesStatusEnum.NotificationAcknowledged: model.NewDate = model.NotificationAcknowledgedDate; break; case KeyDatesStatusEnum.NotificationDecisionDateEntered: model.NewDate = model.DecisionDate; break; } }
public async Task <ActionResult> Index(Guid id, KeyDatesStatusEnum?command) { var data = await mediator.SendAsync(new GetKeyDatesSummaryInformation(id)); var model = new DateInputViewModel(data.Dates) { IsAreaAssigned = data.IsLocalAreaSet, CompetentAuthority = data.CompetentAuthority, AssessmentDecisions = data.DecisionHistory, IsInterim = data.IsInterim }; if (command != null) { model.Command = command.GetValueOrDefault(); AddRelevantDateToNewDate(model); } model.ShowAssessmentDecisionLink = await authorizationService.AuthorizeActivity( ExportNotificationPermissions.CanMakeExportNotificationAssessmentDecision); return(View(model)); }
public async Task<ActionResult> Index(Guid id, KeyDatesStatusEnum? command) { var data = await mediator.SendAsync(new GetKeyDatesSummaryInformation(id)); var model = new DateInputViewModel(data.Dates) { IsAreaAssigned = data.IsLocalAreaSet, CompetentAuthority = data.CompetentAuthority, AssessmentDecisions = data.DecisionHistory, IsInterim = data.IsInterim }; if (command != null) { model.Command = command.GetValueOrDefault(); AddRelevantDateToNewDate(model); } model.ShowAssessmentDecisionLink = await authorizationService.AuthorizeActivity( ExportNotificationPermissions.CanMakeExportNotificationAssessmentDecision); return View(model); }
private async Task FileClosed(DateInputViewModel model) { var fileClosed = new SetNotifcationFileClosedDate(model.NotificationId, model.NewDate.AsDateTime().GetValueOrDefault()); await mediator.SendAsync(fileClosed); }
private async Task SetAcknowledged(DateInputViewModel model) { var setAcknowledged = new SetNotificationAcknowledgedDate(model.NotificationId, model.NewDate.AsDateTime().GetValueOrDefault()); await mediator.SendAsync(setAcknowledged); }
private async Task SetAssessmentCommenced(DateInputViewModel model) { var setAssessmentCommenced = new SetCommencedDate(model.NotificationId, model.NewDate.AsDateTime().GetValueOrDefault(), model.NameOfOfficer); await mediator.SendAsync(setAssessmentCommenced); }
private async Task SetNotificationComplete(DateInputViewModel model) { var setNotificationComplete = new SetNotificationCompleteDate(model.NotificationId, model.NewDate.AsDateTime().GetValueOrDefault()); await mediator.SendAsync(setNotificationComplete); }
private async Task Date_InvalidInput_ValidationError(KeyDatesStatusEnum command) { var model = new DateInputViewModel(); model.Command = command; var controller = GetMockAssessmentController(model); await controller.Index(model); Assert.True(controller.ModelState.ContainsKey("NewDate")); }
public async Task AssessmentCommenced_InvalidInput_ValidationError() { var model = new DateInputViewModel(); model.Command = KeyDatesStatusEnum.AssessmentCommenced; var controller = GetMockAssessmentController(model); await controller.Index(model); Assert.True(controller.ModelState.ContainsKey("NewDate") && controller.ModelState.ContainsKey("NameOfOfficer")); }
private DateInputViewModel GetDecisionRequiredDateModel(int day, int month, int year) { DateInputViewModel model = new DateInputViewModel(); model.DecisionDate = new OptionalDateInputViewModel(); model.DecisionDate.Day = day; model.DecisionDate.Month = month; model.DecisionDate.Year = year; return(model); }
public async Task NotificationReceived_ValidInput_NoValidationError() { var model = new DateInputViewModel(); model.NewDate = new OptionalDateInputViewModel(notificationReceivedDate); model.Command = KeyDatesStatusEnum.NotificationReceived; var controller = GetMockAssessmentController(model); await controller.Index(model); Assert.True(controller.ModelState.IsValid); }
private DateInputViewModel GetValidViewModel() { var model = new DateInputViewModel(); model.NotificationReceivedDate = new OptionalDateInputViewModel(notificationReceivedDate); model.PaymentReceivedDate = paymentReceivedDate; model.CommencementDate = new OptionalDateInputViewModel(commencementDate); model.NotificationCompleteDate = new OptionalDateInputViewModel(completeDate); model.NotificationTransmittedDate = new OptionalDateInputViewModel(transmittedDate); model.NewDate = new OptionalDateInputViewModel(SystemTime.UtcNow.AddDays(1)); return(model); }
public async Task AssessmentCommenced_OfficerNameToLong_ValidationError() { var model = new DateInputViewModel(); model.NewDate = new OptionalDateInputViewModel(commencementDate); model.NameOfOfficer = GetLongString(); model.Command = KeyDatesStatusEnum.AssessmentCommenced; var controller = GetMockAssessmentController(model); await controller.Index(model); Assert.True(controller.ModelState.ContainsKey("NameOfOfficer")); }
public DateRangeInputViewModel( string id, string label, DateInputViewModel startDateModel, DateInputViewModel endDateModel, CheckboxItemViewModel endDateCheckboxViewModel, string?hintText = null ) { Id = id; Label = label; StartDateModel = startDateModel; EndDateModel = endDateModel; EndDateCheckbox = endDateCheckboxViewModel; HintText = hintText; }
public async Task<ActionResult> Index(DateInputViewModel model) { if (!ModelState.IsValid) { model.ShowAssessmentDecisionLink = await authorizationService.AuthorizeActivity( ExportNotificationPermissions.CanMakeExportNotificationAssessmentDecision); return View(model); } if (model.Command == KeyDatesStatusEnum.NotificationReceived) { await SetNotificationReceived(model); } else if (model.Command == KeyDatesStatusEnum.AssessmentCommenced) { await SetAssessmentCommenced(model); } else if (model.Command == KeyDatesStatusEnum.NotificationComplete) { await SetNotificationComplete(model); } else if (model.Command == KeyDatesStatusEnum.NotificationTransmitted) { await SetNotificationTransmitted(model); } else if (model.Command == KeyDatesStatusEnum.NotificationAcknowledged) { await SetAcknowledged(model); } else if (model.Command == KeyDatesStatusEnum.FileClosed) { await FileClosed(model); } else if (model.Command == KeyDatesStatusEnum.ArchiveReference) { await SetArchiveReference(model); } else { throw new InvalidOperationException(); } return RedirectToAction("Index", new { id = model.NotificationId }); }
public async Task <ActionResult> Index(DateInputViewModel model) { if (!ModelState.IsValid) { model.ShowAssessmentDecisionLink = await authorizationService.AuthorizeActivity( ExportNotificationPermissions.CanMakeExportNotificationAssessmentDecision); return(View(model)); } if (model.Command == KeyDatesStatusEnum.NotificationReceived) { await SetNotificationReceived(model); } else if (model.Command == KeyDatesStatusEnum.AssessmentCommenced) { await SetAssessmentCommenced(model); } else if (model.Command == KeyDatesStatusEnum.NotificationComplete) { await SetNotificationComplete(model); } else if (model.Command == KeyDatesStatusEnum.NotificationTransmitted) { await SetNotificationTransmitted(model); } else if (model.Command == KeyDatesStatusEnum.NotificationAcknowledged) { await SetAcknowledged(model); } else if (model.Command == KeyDatesStatusEnum.FileClosed) { await FileClosed(model); } else if (model.Command == KeyDatesStatusEnum.ArchiveReference) { await SetArchiveReference(model); } else { throw new InvalidOperationException(); } return(RedirectToAction("Index", new { id = model.NotificationId })); }
/// <summary> /// Render DateInput view component. /// </summary> /// <param name="id"></param> /// <param name="label"></param> /// <param name="dayId"></param> /// <param name="monthId"></param> /// <param name="yearId"></param> /// <param name="cssClass">Leave blank for no custom css class.</param> /// <param name="hintTextLines">Leave blank for no hint.</param> /// <returns></returns> public IViewComponentResult Invoke( string id, string label, string dayId, string monthId, string yearId, string cssClass, IEnumerable <string>?hintTextLines ) { var model = ViewData.Model; var dayProperty = model.GetType().GetProperty(dayId); var monthProperty = model.GetType().GetProperty(monthId); var yearProperty = model.GetType().GetProperty(yearId); var dayValue = dayProperty?.GetValue(model)?.ToString(); var monthValue = monthProperty?.GetValue(model)?.ToString(); var yearValue = yearProperty?.GetValue(model)?.ToString(); var dayErrors = ViewData.ModelState[dayProperty?.Name]?.Errors ?? new ModelErrorCollection(); var monthErrors = ViewData.ModelState[monthProperty?.Name]?.Errors ?? new ModelErrorCollection(); var yearErrors = ViewData.ModelState[yearProperty?.Name]?.Errors ?? new ModelErrorCollection(); var allErrors = dayErrors.Concat(monthErrors).Concat(yearErrors); var nonEmptyErrors = allErrors.Where(e => !string.IsNullOrWhiteSpace(e.ErrorMessage)) .Select(e => e.ErrorMessage); var viewModel = new DateInputViewModel( id, label, dayId, monthId, yearId, dayValue, monthValue, yearValue, dayErrors?.Count > 0, monthErrors?.Count > 0, yearErrors?.Count > 0, nonEmptyErrors, string.IsNullOrEmpty(cssClass) ? null : cssClass, hintTextLines.Any() ? hintTextLines : null ); return(View(viewModel)); }
private async Task SetArchiveReference(DateInputViewModel model) { await mediator.SendAsync(new SetArchiveReference(model.NotificationId, model.ArchiveReference)); }
private DateInputViewModel GetDecisionRequiredDateModel(int day, int month, int year) { DateInputViewModel model = new DateInputViewModel(); model.DecisionDate = new OptionalDateInputViewModel(); model.DecisionDate.Day = day; model.DecisionDate.Month = month; model.DecisionDate.Year = year; return model; }
/// <summary> /// Render DateInput view component. /// </summary> /// <param name="id"></param> /// <param name="label"></param> /// <param name="startDayId"></param> /// <param name="startMonthId"></param> /// <param name="startYearId"></param> /// <param name="endDayId"></param> /// <param name="endMonthId"></param> /// <param name="endYearId"></param> /// <param name="endDateCheckboxId"></param> /// <param name="endDateCheckboxLabel"></param> /// <param name="hintText">Leave blank for no hint.</param> /// <param name="endDateCheckboxHintText">Leave blank for no hint.</param> /// <returns></returns> public IViewComponentResult Invoke( string id, string label, string startDayId, string startMonthId, string startYearId, string endDayId, string endMonthId, string endYearId, string endDateCheckboxId, string endDateCheckboxLabel, string hintText, string endDateCheckboxHintText ) { var model = ViewData.Model; var(startDayValue, startDayErrors) = GetStringValueAndErrorsForProperty(model, startDayId); var(startMonthValue, startMonthErrors) = GetStringValueAndErrorsForProperty(model, startMonthId); var(startYearValue, startYearErrors) = GetStringValueAndErrorsForProperty(model, startYearId); var(endDayValue, endDayErrors) = GetStringValueAndErrorsForProperty(model, endDayId); var(endMonthValue, endMonthErrors) = GetStringValueAndErrorsForProperty(model, endMonthId); var(endYearValue, endYearErrors) = GetStringValueAndErrorsForProperty(model, endYearId); var checkboxProperty = model.GetType().GetProperty(endDateCheckboxId); var checkboxValue = (bool)checkboxProperty?.GetValue(model) !; var checkboxViewModel = new CheckboxItemViewModel( endDateCheckboxId, endDateCheckboxId, endDateCheckboxLabel, checkboxValue, endDateCheckboxHintText, null ); var allStartDateErrors = (startDayErrors ?? new ModelErrorCollection()) .Concat(startMonthErrors ?? new ModelErrorCollection()) .Concat(startYearErrors ?? new ModelErrorCollection()); var nonEmptyStartDateErrors = allStartDateErrors.Where(e => !string.IsNullOrWhiteSpace(e.ErrorMessage)) .Select(e => e.ErrorMessage); var startDateModel = new DateInputViewModel( "start-date", "Start date", startDayId, startMonthId, startYearId, startDayValue, startMonthValue, startYearValue, startDayErrors?.Count > 0, startMonthErrors?.Count > 0, startYearErrors?.Count > 0, nonEmptyStartDateErrors, "nhsuk-u-margin-bottom-3" ); var allEndDateErrors = (endDayErrors ?? new ModelErrorCollection()) .Concat(endMonthErrors ?? new ModelErrorCollection()) .Concat(endYearErrors ?? new ModelErrorCollection()); var nonEmptyEndDateErrors = allEndDateErrors.Where(e => !string.IsNullOrWhiteSpace(e.ErrorMessage)) .Select(e => e.ErrorMessage); var endDateModel = new DateInputViewModel( "conditional-end-date", "End date", endDayId, endMonthId, endYearId, endDayValue, endMonthValue, endYearValue, endDayErrors?.Count > 0, endMonthErrors?.Count > 0, endYearErrors?.Count > 0, nonEmptyEndDateErrors, "nhsuk-checkboxes__conditional" + (!checkboxValue ? " nhsuk-checkboxes__conditional--hidden" : "") ); var viewModel = new DateRangeInputViewModel( id, label, startDateModel, endDateModel, checkboxViewModel, string.IsNullOrEmpty(hintText) ? null : hintText ); return(View(viewModel)); }
private DateInputViewModel GetValidViewModel() { var model = new DateInputViewModel(); model.NotificationReceivedDate = new OptionalDateInputViewModel(notificationReceivedDate); model.PaymentReceivedDate = paymentReceivedDate; model.CommencementDate = new OptionalDateInputViewModel(commencementDate); model.NotificationCompleteDate = new OptionalDateInputViewModel(completeDate); model.NotificationTransmittedDate = new OptionalDateInputViewModel(transmittedDate); model.NewDate = new OptionalDateInputViewModel(SystemTime.UtcNow.AddDays(1)); return model; }