Ejemplo n.º 1
0
        public async Task <IActionResult> CreateArtist([FromBody] ArtistCreateRequest postRequest)
        {
            try
            {
                var  post   = _mapper.Map <ArtistModel>(postRequest);
                bool exists = await _artistService.ArtistNameExistsAsync(post);

                if (exists)
                {
                    return(BadRequest(new ErrorResponse(ErrorMessages.Artist.NameExists)));
                }

                var artist = await _artistService.CreateArtistAsync(post);

                var locationUri = ApiRoutes.Artists.Route + "/" + artist.ArtistId;
                return(Created(locationUri, new Response <ArtistResponse>(_mapper.Map <ArtistResponse>(artist))));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorResponse(ErrorMessages.Artist.FailedCreate)));
            }
        }