Ejemplo n.º 1
0
        public async Task <GetOverlappingApprenticeshipsQueryResponse> Handle(GetOverlappingApprenticeshipsQueryRequest request)
        {
            var apprenticeships = request.Apprenticeship
                                  .Where(m =>
                                         m.StartDate != null &&
                                         m.EndDate != null &&
                                         !string.IsNullOrEmpty(m.ULN))
                                  .ToList();

            if (!apprenticeships.Any())
            {
                return(new GetOverlappingApprenticeshipsQueryResponse
                {
                    Overlaps = Enumerable.Empty <ApprenticeshipOverlapValidationResult>()
                });
            }

            return(new GetOverlappingApprenticeshipsQueryResponse
            {
                Overlaps = await _validationApi
                           .ValidateOverlapping(apprenticeships.Select(arg =>
                                                                       new ApprenticeshipOverlapValidationRequest
                {
                    ApprenticeshipId = arg.Id,
                    Uln = arg.ULN,
                    StartDate = arg.StartDate.Value,
                    EndDate = arg.EndDate.Value
                }))
            });
        }
        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());
        }