public async Task <IActionResult> Create(CreateArtistInputModel input) { if (!ModelState.IsValid) { return(View(input)); } if (!await artistService.CreateArtistAsync(input)) { return(View(input)); } return(Redirect(redirectArtistsAllAndOrder)); }
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))); } }