private bool BeGreaterThenStartDate(ApprenticeshipViewModel viewModel, DateTimeViewModel date) { if (viewModel.StartDate?.DateTime == null || viewModel.EndDate?.DateTime == null) { return(true); } return(viewModel.StartDate.DateTime < viewModel.EndDate.DateTime); }
public void ShouldBeValidPast() { var year = DateTime.Now.Year - 5; var yearTwoDigit = int.Parse(year.ToString().Substring(2)); var sut = new DateTimeViewModel(null, 2, yearTwoDigit, 0); (sut.DateTime == null).Should().BeFalse(); sut.DateTime?.ToString("dd/MM/yyyy").Should().Be("01/02/" + year); }
public KeyValuePair <string, string>?CheckEndDateInFuture(DateTimeViewModel endDate) { const string endDateKey = "EndDate"; var now = CurrentDateTime.Now; return(new DateTime(endDate.Year.Value, endDate.Month.Value, 1) > new DateTime(now.Year, now.Month, 1) ? (KeyValuePair <string, string>?)null : new KeyValuePair <string, string>(endDateKey, ValidationText.LearnPlanEndDate03.Text)); }
public ActionResult PassUsingModel() { var current = this.dataTimeService.Now; var model = new DateTimeViewModel { Current = current }; return(this.View(model)); }
private bool ValidateDateOfBirth(DateTimeViewModel date) { // Check the day has value as the view model supports just month and year entry if (date.DateTime == null || !date.Day.HasValue) { return(false); } return(true); }
private bool ApprenticeDobMustBeGreaterThenMinimumDob(DateTimeViewModel dob) { DateTime?dobDate = dob?.DateTime; DateTime minimumDataOfBirth = new DateTime(1900, 01, 01, 0, 0, 0, DateTimeKind.Utc); if (dobDate == null) { return(true); } return(dobDate > minimumDataOfBirth); }
public void ShouldPassValidationForPlanedEndDateInFuture(int monthsToAdd, int currentDay) { CurrentDateTime.Setup(x => x.Now).Returns(new DateTime(2019, 3, currentDay)); var endDate = new DateTimeViewModel(CurrentDateTime.Object.Now.AddMonths(monthsToAdd)) { Day = 1 }; var result = Validator.CheckEndDateInFuture(endDate); result.HasValue.Should().BeFalse(); }
public void ShouldFailValidationForPlanedEndDateNotInFuture(int monthsToAdd, int currentDay) { CurrentDateTime.Setup(x => x.Now).Returns(new DateTime(2019, 3, currentDay)); var endDate = new DateTimeViewModel(CurrentDateTime.Object.Now.AddMonths(monthsToAdd)) { Day = 1 }; var result = Validator.CheckEndDateInFuture(endDate); result.HasValue.Should().BeTrue(); result.Value.Key.Should().Be("EndDate"); result.Value.Value.Should().Be("The end date must not be in the past"); }
private bool HasYearOrMonthValueSet(DateTimeViewModel date) { if (date == null) { return(false); } if (date.Day.HasValue || date.Month.HasValue || date.Year.HasValue) { return(true); } return(false); }
private bool HasAnyValuesSet(DateTimeViewModel dateOfBirth) { if (dateOfBirth == null) { return(false); } if (dateOfBirth.Day.HasValue || dateOfBirth.Month.HasValue || dateOfBirth.Year.HasValue) { return(true); } return(false); }
public async Task <IHttpActionResult> ValidateGroupOpenDate(DateTimeViewModel openDate) { if (openDate == null || openDate.IsEmpty()) { ModelState.AddModelError("openDate", "Date cannot be empty"); } if (!ModelState.IsValid) { return(Json(ModelState.Where(m => m.Value.Errors.Any()))); } return(Json(new string[] { })); }
private async Task <DownloadsViewModel> GetDownloads(int?skip, DateTimeViewModel filterDate, eDownloadFilter searchType = eDownloadFilter.Latest) { var dateLookup = searchType == eDownloadFilter.Latest ? new DateTimeViewModel(DateTime.Today) : filterDate.IsValid() ? filterDate : new DateTimeViewModel(DateTime.Today); var viewModel = new DownloadsViewModel { Downloads = await _downloadsService.GetListAsync(dateLookup.ToDateTime() ?? DateTime.Today, User), ScheduledExtracts = await _downloadsService.GetScheduledExtractsAsync(skip.GetValueOrDefault(), 100, User), FilterDate = dateLookup, SearchType = searchType, Skip = skip }; return(viewModel); }
public async Task <IActionResult> GetAppointment(DateTimeViewModel input, string id) { var currentUser = await userManager.GetUserAsync(User); var dentist = await userManager.FindByIdAsync(id); var appointment = new Appointment { Dentist = dentist.Id, Patient = currentUser.Id, Date = input.Appointment, UserId = currentUser.Id }; db.Appointments.Add(appointment); db.SaveChanges(); return(RedirectToAction("AllAppointments", appointment)); } //OK
private bool NotBeBeforeMay2017(DateTimeViewModel date) { return(date.DateTime >= new DateTime(2017, 5, 1)); }
private bool ValidateDateWithoutDay(DateTimeViewModel date) { return(date.DateTime != null); }
private bool StartDateForTransferNotBeforeMay2018(ApprenticeshipViewModel viewModel, DateTimeViewModel date) { return(!viewModel.IsPaidForByTransfer || date.DateTime >= new DateTime(2018, 5, 1)); }
private bool StartDateWithinAYearOfTheEndOfTheCurrentTeachingYear(DateTimeViewModel startDate) { return(startDate.DateTime.Value <= _academicYear.CurrentAcademicYearEndDate.AddYears(1)); }
private bool HasAnyValuesSet(DateTimeViewModel dateOfBirth) { return(dateOfBirth != null && (dateOfBirth.Day.HasValue || dateOfBirth.Month.HasValue || dateOfBirth.Year.HasValue)); }
public void ShouldBeValid() { var sut = new DateTimeViewModel(DateTime.Parse("2009-09-25")); sut.DateTime?.ToString("dd/MM/yyyy").Should().Be("25/09/2009"); }
private bool StartDateForTransferNotBeforeMay2018(ApprenticeshipViewModel viewModel, DateTimeViewModel date) { if (!viewModel.IsPaidForByTransfer || date.DateTime >= new DateTime(2018, 5, 1)) { return(true); } //Add alternative detail error message to dummy property viewModel.StartDateTransfersMinDateAltDetailMessage = "The start date can't be earlier than May 2018"; return(false); }
private bool NotEmptyDate(DateTimeViewModel dateTimeViewModel) { return(dateTimeViewModel.Day.HasValue || dateTimeViewModel.Month.HasValue || dateTimeViewModel.Year.HasValue); }
public async Task <ActionResult> Index(int?skip, DateTimeViewModel filterDate, eDownloadFilter searchType = eDownloadFilter.Latest) { var viewModel = await GetDownloads(skip, filterDate, searchType); return(View(viewModel)); }
private bool ValidateDateOfBirth(DateTimeViewModel date) { // Check the day has value as the view model supports just month and year entry return(date.DateTime != null && date.Day.HasValue); }
public void ShouldBeValidFuture(int?day, int?month, int?year, string expected) { var sut = new DateTimeViewModel(day, month, year); sut.DateTime?.ToString("dd/MM/yyyy").Should().Be(expected); }
private async Task <bool> TrainingCourseValidOnStartDate(ApprenticeshipViewModel viewModel, DateTimeViewModel startDate, PropertyValidatorContext context) { if (viewModel.IsContinuation) { return(true); } if (string.IsNullOrWhiteSpace(viewModel.TrainingCode) || (!startDate.DateTime.HasValue)) { return(true); } var result = await Mediator.SendAsync(new GetTrainingProgrammesQueryRequest { EffectiveDate = null, IncludeFrameworks = true }); var course = result.TrainingProgrammes.Single(x => x.CourseCode == viewModel.TrainingCode); var courseStatus = course.GetStatusOn(startDate.DateTime.Value); if (courseStatus == TrainingProgrammeStatus.Active) { return(true); } var suffix = courseStatus == TrainingProgrammeStatus.Pending ? $"after {course.EffectiveFrom.Value.AddMonths(-1):MM yyyy}" : $"before {course.EffectiveTo.Value.AddMonths(1):MM yyyy}"; context.MessageFormatter.AppendArgument("suffix", suffix); return(false); }
private bool WillApprenticeBeAtLeast15AtStartOfTraining(ApprenticeshipViewModel model, DateTimeViewModel dob) { DateTime?startDate = model?.StartDate?.DateTime; DateTime?dobDate = dob?.DateTime; if (startDate == null || dob == null) { return(true); // Don't fail validation if both fields not set } int age = startDate.Value.Year - dobDate.Value.Year; if (startDate < dobDate.Value.AddYears(age)) { age--; } return(age >= 15); }
private bool HasYearOrMonthValueSet(DateTimeViewModel date) { //todo: this looks suspiciously like HasAnyValuesSet() below, not year or month! return(date != null && (date.Day.HasValue || date.Month.HasValue || date.Year.HasValue)); }
private bool WillApprenticeBeNoMoreThan115AtTheStartOfTheCurrentTeachingYear(DateTimeViewModel dob) { var age = _academicYear.CurrentAcademicYearStartDate.Year - dob.DateTime.Value.Year; return(age <= 115); }
public ChangeStatusViewModel() { DateOfChange = new DateTimeViewModel(); }
private async Task <bool> NotOverlap(EditApprenticeshipStopDateViewModel model, DateTimeViewModel viewModel, CancellationToken arg3) { if (model.NewStopDate.DateTime <= model.CurrentStopDate) { return(true); } var apprenticeshipId = _hashingService.DecodeValue(model.ApprenticeshipHashedId); var overlapResult = await _validationApi.ValidateOverlapping(new ApprenticeshipOverlapValidationRequest { ApprenticeshipId = apprenticeshipId, StartDate = model.ApprenticeshipStartDate, EndDate = model.NewStopDate.DateTime.Value, Uln = model.ApprenticeshipULN }); return(overlapResult == null || !overlapResult.OverlappingApprenticeships.Any()); }