Exemple #1
0
        public async Task <IActionResult> AddLibraryAsync([FromBody] Library library, string languageId)
        {
            if (languageId.Length != 24)
            {
                return(BadRequest(new { error = new { message = $"Language Id should be a 24 characters hex string" } }));
            }

            if (library.LanguageId != languageId)
            {
                ModelState.AddModelError("Language unmatch", "Framework Id does not match an existing framework");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var errors = await _errorService.GetUriErrors(languageId);

                if (errors.Count != 0)
                {
                    return(NotFound(errors));
                }

                await _libraryService.AddLibraryAsync(library);
            }
            catch (Exception exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { error = new { message = exception.Message } }));
            }



            return(library.Id != null ? (IActionResult)Ok(library.Id) : BadRequest());
        }