public async Task <ActionResult <GenreModel> > Post(GenreModel model) { try { var existing = _repository.CheckForExistingGenreName(model.Name); if (existing) { return(BadRequest($"The genre, {model.Name}, already exists in database.")); } var genre = _mapper.Map <Genre>(model); var genreId = _repository.GenerateGenreId(); var location = _linkGenerator.GetPathByAction("Get", "Genres", new { genreId = genreId.Id }); _repository.Add(genre); if (await _repository.SaveChangesAsync()) { return(Created(location, _mapper.Map <GenreModel>(genre))); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } return(BadRequest()); }