コード例 #1
0
        public override ValidationResult Validate()
        {
            string message = _validationObject switch
            {
                GetUserResourceUsageReportModel model => ValidateGetUserResourceUsageReportModel(model),
                GetResourceUsageReportForJobModel model => ValidateGetResourceUsageReportForJobModel(model),
                GetUserGroupResourceUsageReportModel model => ValidateGetUserGroupResourceUsageReportModel(model),
                ListAdaptorUserGroupsModel model => ValidateListAdaptorUserGroupsModel(model),
                _ => string.Empty
            };

            return(new ValidationResult(string.IsNullOrEmpty(message), message));
        }
コード例 #2
0
        private string ValidateGetUserGroupResourceUsageReportModel(GetUserGroupResourceUsageReportModel model)
        {
            ValidateId(model.GroupId, nameof(model.GroupId));
            if (model.StartTime > model.EndTime)
            {
                _messageBuilder.AppendLine("StartTime must be before EndTime");
            }

            ValidationResult validationResult = new SessionCodeValidator(model.SessionCode).Validate();

            if (!validationResult.IsValid)
            {
                _messageBuilder.AppendLine(validationResult.Message);
            }

            return(_messageBuilder.ToString());
        }
コード例 #3
0
        public IActionResult GetUserGroupResourceUsageReport(GetUserGroupResourceUsageReportModel model)
        {
            try
            {
                _logger.LogDebug($"Endpoint: \"JobReporting\" Method: \"GetUserGroupResourceUsageReport\" Parameters: \"{model}\"");
                ValidationResult validationResult = new JobReportingValidator(model).Validate();
                if (!validationResult.IsValid)
                {
                    ExceptionHandler.ThrowProperExternalException(new InputValidationException(validationResult.Message));
                }

                return(Ok(_service.GetUserGroupResourceUsageReport(model.GroupId, model.StartTime, model.EndTime, model.SessionCode)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }