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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        public ActionResult PassUsingModel()
        {
            var current = this.dataTimeService.Now;
            var model   = new DateTimeViewModel
            {
                Current = current
            };

            return(this.View(model));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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");
        }
Esempio n. 9
0
        private bool HasYearOrMonthValueSet(DateTimeViewModel date)
        {
            if (date == null)
            {
                return(false);
            }

            if (date.Day.HasValue || date.Month.HasValue || date.Year.HasValue)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 13
0
        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
Esempio n. 14
0
 private bool NotBeBeforeMay2017(DateTimeViewModel date)
 {
     return(date.DateTime >= new DateTime(2017, 5, 1));
 }
Esempio n. 15
0
 private bool ValidateDateWithoutDay(DateTimeViewModel date)
 {
     return(date.DateTime != null);
 }
Esempio n. 16
0
 private bool StartDateForTransferNotBeforeMay2018(ApprenticeshipViewModel viewModel, DateTimeViewModel date)
 {
     return(!viewModel.IsPaidForByTransfer || date.DateTime >= new DateTime(2018, 5, 1));
 }
Esempio n. 17
0
 private bool StartDateWithinAYearOfTheEndOfTheCurrentTeachingYear(DateTimeViewModel startDate)
 {
     return(startDate.DateTime.Value <= _academicYear.CurrentAcademicYearEndDate.AddYears(1));
 }
Esempio n. 18
0
 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);
        }
Esempio n. 21
0
 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));
        }
Esempio n. 23
0
 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);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
 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));
 }
Esempio n. 28
0
        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());
        }