public override ValidationResult Validate() { string message = _validationObject switch { CreateCommandTemplateModel ext => ValidateCreateCommandTemplateModel(ext), ModifyCommandTemplateModel ext => ValidateModifyCommandTemplateModel(ext), RemoveCommandTemplateModel ext => ValidateRemoveCommandTemplateModel(ext), _ => string.Empty }; return(new ValidationResult(string.IsNullOrEmpty(message), message)); }
private string ValidateModifyCommandTemplateModel(ModifyCommandTemplateModel model) { ValidateId(model.CommandTemplateId, nameof(model.CommandTemplateId)); ValidationResult sessionCodeValidation = new SessionCodeValidator(model.SessionCode).Validate(); if (!sessionCodeValidation.IsValid) { _messageBuilder.AppendLine(sessionCodeValidation.Message); } if (ContainsIllegalCharactersForPath(model.ExecutableFile)) { _messageBuilder.AppendLine("ExecutableFile contains illegal characters."); } return(_messageBuilder.ToString()); }
public IActionResult ModifyCommandTemplate(ModifyCommandTemplateModel model) { try { _logger.LogDebug($"Endpoint: \"Management\" Method: \"ModifyCommandTemplate\""); ValidationResult validationResult = new ManagementValidator(model).Validate(); if (!validationResult.IsValid) { ExceptionHandler.ThrowProperExternalException(new InputValidationException(validationResult.Message)); } return(Ok(_service.ModifyCommandTemplate(model.CommandTemplateId, model.Name, model.Description, model.Code, model.ExecutableFile, model.PreparationScript, model.SessionCode))); } catch (Exception e) { return(BadRequest(e.Message)); } }