Ejemplo n.º 1
0
        public async Task <ActionResult <ArtistRessource> > CreateArtist(SaveArtistRessource saveArtistRessource)
        {
            try
            {
                var validation       = new SaveArtistRessourceValidator();
                var validationResult = await validation.ValidateAsync(saveArtistRessource);

                if (!validationResult.IsValid)
                {
                    return(BadRequest(validationResult.Errors));
                }
                //=== mappage artiste
                var artist = _mapperService.Map <SaveArtistRessource, Artist>(saveArtistRessource);
                //====Creation New Artist====
                var artistNew = await _artistService.CreateArtist(artist);

                // ========Mappage Artiste sur ArtisteRessource===
                var artisteRessource = _mapperService.Map <Artist, ArtistRessource>(artistNew);
                return(Ok(artisteRessource));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ArtistRessource> > UpdateArtistById(int id, SaveArtistRessource saveArtistRessource)
        {
            try
            {
                var validation       = new SaveArtistRessourceValidator();
                var validationResult = await validation.ValidateAsync(saveArtistRessource);

                if (!validationResult.IsValid)
                {
                    return(BadRequest(validationResult.Errors));
                }
                //======= verif Artist======
                var artist = await _artistService.GetArtistById(id);

                if (artist == null)
                {
                    return(BadRequest(" artist n'existe pas !"));
                }
                // ========Mappage Sur noveau Artiste ====
                var artistModif = _mapperService.Map <SaveArtistRessource, Artist>(saveArtistRessource);
                // ======Update Artiste ======
                await _artistService.UpdateArtist(artist, artistModif);

                //======Get New Artist ======
                var artistNew = await _artistService.GetArtistById(id);

                // ====Mappage ======
                var artisteRessource = _mapperService.Map <Artist, ArtistRessource>(artistNew);

                return(Ok(artisteRessource));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }