Beispiel #1
0
        public async Task <IActionResult> PostAsync([FromBody] ProjectedNoticeDateCalculationRequestModel data)
        {
            if (data == null)
            {
                ModelState.AddModelError("",
                                         "Bad payload provided; unable to parse the request , please review request data and try again");
                _logger.LogError(400, $"Bad payload " +
                                 $"{ModelState}\n Request Data is null and could not be parsed");
                return(BadRequest(ModelState));
            }

            var validator = new ProjectedNoticeDateCalculationRequestValidator();

            if (!ModelState.IsValid || !validator.Validate(data).IsValid)
            {
                _logger.LogError((int)HttpStatusCode.BadRequest, $"Request model not valid " +
                                 $"{ModelState}\n Request Data {JsonConvert.SerializeObject(data)} \n Errors : " +
                                 $"{validator.Validate(data).Errors.GetErrorsAsString()} ");
                return(BadRequest(ModelState));
            }

            var result = await _pndCalculationService.PerformProjectedNoticeDateCalculationAsync(data, _options);

            _logger.LogInformation((int)HttpStatusCode.OK,
                                   $"Calculation performed successfully for the request data provided \n Request Data: {JsonConvert.SerializeObject(data)}");
            return(Ok(result));
        }
Beispiel #2
0
        private async Task TestCalculation(ProjectedNoticeDateCalculationRequestModel request, DateTime expectedProjectedNoticeDate, DateTime expectedNoticeStartDate)
        {
            //Act
            var actualResult = await _service.PerformProjectedNoticeDateCalculationAsync(request, _options);

            //Assert
            actualResult.ProjectedNoticeDate.Should().Be(expectedProjectedNoticeDate);
            actualResult.NoticeStartDate.Should().Be(expectedNoticeStartDate);
        }
Beispiel #3
0
        public async Task PerformCalculationAsync_WhenDateNoticeGivenEarliest()
        {
            var request = new ProjectedNoticeDateCalculationRequestModel
            {
                EmploymentStartDate = new DateTime(2016, 02, 01),
                DismissalDate       = new DateTime(2018, 01, 05),
                DateNoticeGiven     = new DateTime(2018, 01, 01)
            };

            await TestCalculation(request, new DateTime(2018, 01, 08), new DateTime(2018, 01, 02));
        }
Beispiel #4
0
        public async Task PerformCalculationAsync_WhenGreaterThan12YearsService()
        {
            var request = new ProjectedNoticeDateCalculationRequestModel
            {
                EmploymentStartDate = new DateTime(2002, 02, 01),
                DismissalDate       = new DateTime(2018, 01, 05),
                DateNoticeGiven     = new DateTime(2018, 01, 01)
            };

            await TestCalculation(request, new DateTime(2018, 03, 26), new DateTime(2018, 01, 02));
        }
        public async Task <ProjectedNoticeDateResponseDTO> PerformProjectedNoticeDateCalculationAsync(ProjectedNoticeDateCalculationRequestModel request, IOptions <ConfigLookupRoot> options)
        {
            var result = new ProjectedNoticeDateResponseDTO();

            var relNoticeDate = (request.DateNoticeGiven < request.DismissalDate) ? request.DateNoticeGiven : request.DismissalDate;

            // number of weeks entitle (based on years served) max 12
            var noticeEntitlementWeeks = await request.EmploymentStartDate.GetServiceYearsAsync(relNoticeDate);

            noticeEntitlementWeeks = Math.Max(Math.Min(noticeEntitlementWeeks, 12), 1);

            result.ProjectedNoticeDate = relNoticeDate.AddDays(noticeEntitlementWeeks * 7);
            result.NoticeStartDate     = relNoticeDate.AddDays(1);
            return(await Task.FromResult(result));
        }