public async Task <ActionResult <ArtistDTO> > UpdateArtistById(int id, [FromBody] SaveArtistDTO saveArtistDTO)
        {
            var validation = new SaveArtistResourceValidator();

            var validationResource = await validation.ValidateAsync(saveArtistDTO);

            if (id == 0 || !validationResource.IsValid)
            {
                return(BadRequest(validationResource.Errors));
            }

            var artistToBeUpdate = await _artistService.GetArtistById(id);

            if (artistToBeUpdate == null)
            {
                return(NotFound());
            }

            var artist = _mapper.Map <SaveArtistDTO, Artist>(saveArtistDTO);

            await _artistService.UpdateArtist(artistToBeUpdate, artist);

            var updateArtist = await _artistService.GetArtistById(id);

            var updateArtistResource = _mapper.Map <Artist, ArtistDTO>(updateArtist);

            return(Ok(updateArtistResource));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <ArtistDTO> > UpdateArtist(int id, [FromBody] SaveArtistDTO saveArtistResource)
        {
            var validator        = new SaveArtistResourceValidator();
            var validationResult = await validator.ValidateAsync(saveArtistResource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors)); // this needs refining, but for demo it is ok
            }
            var artistToBeUpdated = await _artistService.GetArtistById(id);

            if (artistToBeUpdated == null)
            {
                return(NotFound());
            }

            var artist = _mapper.Map <SaveArtistDTO, Artist>(saveArtistResource);

            await _artistService.UpdateArtist(artistToBeUpdated, artist);

            var updatedArtist = await _artistService.GetArtistById(id);

            var updatedArtistResource = _mapper.Map <Artist, ArtistDTO>(updatedArtist);

            return(Ok(updatedArtistResource));
        }
Exemplo n.º 3
0
        public async Task <ArtistDTO> UpdateArtist(ArtistDTO artistToBeUpdated, SaveArtistDTO artist)
        {
            var newArtist      = _mapper.Map <SaveArtistDTO, ArtistDTO>(artist);
            var newArtistBasic = _mapper.Map <ArtistDTO, Artist>(artistToBeUpdated);

            newArtistBasic.Name = newArtist.Name;
            await _unitOfWork.CommitAsync();

            return(await GetArtistById(newArtistBasic.Id));
        }
Exemplo n.º 4
0
        public async Task <ArtistDTO> CreateArtist(SaveArtistDTO newArtist)
        {
            var artistToCreate = _mapper.Map <SaveArtistDTO, Artist>(newArtist);
            await _unitOfWork.Artists.AddAsync(artistToCreate);

            await _unitOfWork.CommitAsync();

            var artist = await GetArtistById(artistToCreate.Id);

            return(artist);
        }
Exemplo n.º 5
0
        public async Task <ActionResult <ArtistDTO> > CreateArtist([FromBody] SaveArtistDTO saveArtistDTO)
        {
            var validator       = new SaveArtistDTOValidator();
            var validatorResult = await validator.ValidateAsync(saveArtistDTO);

            if (!validatorResult.IsValid)
            {
                return(BadRequest(validatorResult.Errors));
            }

            var artist = await _ArtistService.CreateArtist(saveArtistDTO);

            return(Ok(artist));
        }
Exemplo n.º 6
0
        public async Task <ActionResult <ArtistDTO> > CreateArtist([FromBody] SaveArtistDTO saveArtistResource)
        {
            var validator        = new SaveArtistResourceValidator();
            var validationResult = await validator.ValidateAsync(saveArtistResource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors)); // this needs refining, but for demo it is ok
            }
            var artistToCreate = _mapper.Map <SaveArtistDTO, Artist>(saveArtistResource);

            var newArtist = await _artistService.CreateArtist(artistToCreate);

            var artist = await _artistService.GetArtistById(newArtist.Id);

            var artistResource = _mapper.Map <Artist, ArtistDTO>(artist);

            return(Ok(artistResource));
        }
Exemplo n.º 7
0
        public async Task <ActionResult <ArtistDTO> > UpdateArtist(int id, [FromBody] SaveArtistDTO saveArtistDTO)
        {
            var validator       = new SaveArtistDTOValidator();
            var validatorResult = await validator.ValidateAsync(saveArtistDTO);

            var requestIsValid = id == 0 || !validatorResult.IsValid;

            if (requestIsValid)
            {
                return(BadRequest(validatorResult.Errors));
            }

            var artistToBeUpdate = await _ArtistService.GetArtistById(id);

            if (artistToBeUpdate == null)
            {
                return(NotFound());
            }
            var updatedMusicDTO = await _ArtistService.UpdateArtist(artistToBeUpdate, saveArtistDTO);

            return(Ok(updatedMusicDTO));
        }