public async Task <ApiResult <bool> > CreateVersion(CommanderVersion commanderVersion) { ApiResult <bool> response = new ApiResult <bool>(); try { bool isValid = false; string regularExpression = @"^[A-Z\s.0-9#$*()?!+_-]{1,20}$"; Regex regex = new Regex(regularExpression, RegexOptions.Singleline); Match m = regex.Match(commanderVersion.VersionDescription); isValid = m.Success; if (isValid) { response.Result = await _commanderVersionRepository.CreateVersionAsync(commanderVersion); } else { response.AddErrorMessage(CommanderVersionErrorCodes.CommanderCreateversionsVersionFormatErrorMsg.ToString()); } } catch (Exception) { throw; } return(response); }
public async Task <IActionResult> CreateVersion([FromBody] CommanderVersion version) { try { await _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Web Api call for CreateVersion", "CommanderVersionController.cs", "CreateVersion"), CancellationToken.None); var response = await _commanderVersionApi.CreateVersion(version); if (response.IsSuccess) { return(Ok(response.Result)); } else { var msg = this._localizer?[response.ErrorMessages.FirstOrDefault().ToString()]?.Value; await _loggingFacade.LogAsync(new LogEntry(LogLevels.Error, "Web Api call for CreateVersion " + msg, "CommanderVersionController.cs", "CreateVersion"), CancellationToken.None); return(this.StatusCode((int)System.Net.HttpStatusCode.BadRequest, msg)); } } catch (Exception ex) { var msg = this._localizer?[CommanderVersionErrorCodes.CommanderCreateversionsErrorMsg.ToString()]?.Value; await _loggingFacade.LogExceptionAsync(ex, this.HttpContext?.Request?.Headers["UserName"], LogLevels.Error, "Error in Create Version()", CancellationToken.None); return(this.StatusCode((int)System.Net.HttpStatusCode.InternalServerError, msg)); } }