private void ExecuteValidationInArgument <TRequestMessage>(ActionExecutingContext context, TRequestMessage requestMessage)
            where TRequestMessage : RequestMessage
        {
            Configure.SetProtocolToRequest(context, requestMessage);
            Configure.SetOriginIp(context);
            Configure.SetOriginDevice(context);
            Configure.SetCustomHeaders(context, requestMessage);

            var result = new ResultResponseMessage <ResponseMessage>(requestMessage);

            if (requestMessage == null)
            {
                result.CreateResponseBadRequest("The request cannot be null.");
                context.Result = result;
                return;
            }

            if (context.ModelState.IsValid)
            {
                return;
            }

            foreach (KeyValuePair <string, ModelStateEntry> kvp in context.ModelState)
            {
                string          key   = kvp.Key.Split('.').LastOrDefault();
                ModelStateEntry value = kvp.Value;

                if (value.Errors == null || !value.Errors.Any())
                {
                    continue;
                }

                var errorMessage = value.Errors.First().ErrorMessage;

                key = char.ToLowerInvariant(key[0]) + key.Substring(1);

                if (string.IsNullOrWhiteSpace(errorMessage) || errorMessage.ToLower().Contains("field is required"))
                {
                    result.AddValidation(key, "The field " + key + " is required");
                }
                else
                {
                    result.AddValidation(key, value.Errors.FirstOrDefault()?.ErrorMessage);
                }
            }

            result.CreateResponseBadRequest("Fields Validation");
            context.Result = result;
        }
        public static ResultResponseMessage ToResultResponseMessage <TRequestMessage, TModel>(this IModelResult <TModel> modelResult, TRequestMessage requestMessage)
            where TRequestMessage : RequestMessage
            where TModel : IModel
        {
            var result = new ResultResponseMessage(requestMessage);

            if (!modelResult.IsModelResultValid())
            {
                if (modelResult.Validations != null)
                {
                    foreach (var validation in modelResult.Validations)
                    {
                        result.AddValidation(validation.Attribute, validation.Message);
                    }
                }

                result.MapResultResponseMessage((HttpStatusCode)modelResult.ModelStatusCode, modelResult.Message);
            }

            return(result);
        }