public async Task ValidateSocialContextDates_ReturnsErrorIfDateToBeforeDateFrom()
        {
            // Arrange
            var initialPage = await Client.GetAsync(GetCurrentPathForId(Utilities.NOTIFICATION_WITH_ADDRESSES) + ADDRESS_ID);

            var initialDocument = await GetDocumentAsync(initialPage);

            var keyValuePairs = new DatesValidationModel
            {
                KeyValuePairs = new List <Dictionary <string, string> >()
                {
                    new Dictionary <string, string>()
                    {
                        { "key", "DateFrom" },
                        { "day", "1" },
                        { "month", "1" },
                        { "year", "2000" }
                    },
                    new Dictionary <string, string>()
                    {
                        { "key", "DateTo" },
                        { "day", "1" },
                        { "month", "1" },
                        { "year", "1999" }
                    }
                }
            };

            // Act
            var response = await Client.SendVerificationPostAsync(
                initialPage,
                initialDocument,
                GetCurrentPathForId(Utilities.NOTIFICATION_WITH_ADDRESSES) + ADDRESS_ID + "/ValidateSocialContextDates",
                keyValuePairs);

            // Assert check just response.Content
            var result = await response.Content.ReadAsStringAsync();

            Assert.Contains(ValidationMessages.VenueDateToShouldBeLaterThanDateFrom, result);
        }
        public async Task ValidateSocialContextDatesRequest_ReturnsBadRequestIfDateInvalid()
        {
            // Arrange
            var initialPage = await Client.GetAsync(GetCurrentPathForId(Utilities.NOTIFICATION_WITH_ADDRESSES) + ADDRESS_ID);

            var initialDocument = await GetDocumentAsync(initialPage);

            var keyValuePairs = new DatesValidationModel
            {
                KeyValuePairs = new List <Dictionary <string, string> >()
                {
                    new Dictionary <string, string>()
                    {
                        { "key", "DateFrom" },
                        { "day", "1" },
                        { "month", "1" },
                        { "year", "20000301" }
                    },
                    new Dictionary <string, string>()
                    {
                        { "key", "DateTo" },
                        { "day", "1" },
                        { "month", "1" },
                        { "year", "1999" }
                    }
                }
            };

            // Act
            var response = await Client.SendVerificationPostAsync(
                initialPage,
                initialDocument,
                GetCurrentPathForId(Utilities.NOTIFICATION_WITH_ADDRESSES) + ADDRESS_ID + "/ValidateSocialContextDates",
                keyValuePairs);

            // Assert check just response.Content
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public IActionResult OnPostValidateSocialContextDates([FromBody] DatesValidationModel validationData)
        {
            List <(string, object)> propertyValueTuples = new List <(string key, object property)>();

            foreach (var keyValuePair in validationData.KeyValuePairs)
            {
                var formattedDate = new FormattedDate()
                {
                    Day = keyValuePair["day"], Month = keyValuePair["month"], Year = keyValuePair["year"]
                };
                if (formattedDate.TryConvertToDateTime(out var convertedDob))
                {
                    propertyValueTuples.Add((keyValuePair["key"], convertedDob));
                }
                else
                {
                    // As we know that the validation will have already run for each date separately, we don't need to
                    // return any errors as they will already have been displayed.
                    // It would be better if we didn't get to this point if we knew there was an invalid date.
                    return(BadRequest("One or more of the provided dates does not have a valid format."));
                }
            }
            return(ValidationService.GetMultiplePropertiesValidationResult <T>(propertyValueTuples));
        }