예제 #1
0
        public async Task <IActionResult> RegisterScriptType([FromBody] RegisterScriptTypeModel Model)
        {
            _logger.LogInformation("Register new script type");
            try
            {
                ScriptType scriptType = _mapper.Map <ScriptType>(Model);
                scriptType = await _scriptService.CreateTypeAsync(scriptType);

                ScriptTypeModel scriptTypeModel = _mapper.Map <ScriptTypeModel>(scriptType);
                _logger.LogInformation("Registered new script type with id : {id}", scriptTypeModel.Id);
                _logger.LogDebug("New script type : {@scripttype}", scriptType);

                return(Ok(scriptTypeModel));
            }
            catch (AppException ex)
            {
                _logger.LogWarning(ex, "Failed to register script type");
                return(BadRequest(new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Fatal failure during script type registration");
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Fatal internal error. Please contact administrator" }));
            }
        }