public async Task <IActionResult> Post([FromBody] Language value) { try { if (await _service.ExistsAsync(value.Key)) { return(Conflict(new ApiResponse(HttpStatusCode.Conflict, "A language with this key already exists"))); } await _service.Add(value.FromContract()); return(Ok()); } catch (ApplicationException ex) { _logger.LogError(ex, ex.Message); return(BadRequest(new ApiResponse(HttpStatusCode.BadRequest, ex.Message))); } }
private async Task ValidateTranslation(Translation value) { if (!IsValidTranslation(value)) { throw new InvalidOperationException("Translation is invalid"); } if (!await _projectService.ExistsAsync(value.ProjectKey) || !await _languageService.ExistsAsync(value.LanguageKey)) { throw new ApplicationException("Language or Project does not exist"); } }