Exemplo n.º 1
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] ArtistInputModel value)
        {
            if (value == null)
            {
                return(BadRequest("Invalid input"));
            }

            var result = await _artistsService.UpdateAsync(id, value);

            if (result == null)
            {
                return(BadRequest($"Update of artist {id} failed"));
            }

            return(Ok(result));
        }
Exemplo n.º 2
0
        public int CreateNewArtist(ArtistInputModel artist)
        {
            var entity = new Artist
            {
                Name         = artist.Name,
                Bio          = artist.Bio,
                CreatedDate  = DateTime.Now,
                ModifiedDate = DateTime.Now
            };

            _dbContext.Artists.Add(entity);
            // COMMIT
            _dbContext.SaveChanges();

            return(entity.Id);
        }
Exemplo n.º 3
0
        public void UpdateArtist(int id, ArtistInputModel artist)
        {
            var entity = _dbContext.Artists.FirstOrDefault(a => a.Id == id);

            if (entity == null)
            {
                return;
            }

            // Update properties
            entity.Name         = artist.Name;
            entity.Bio          = artist.Bio;
            entity.ModifiedDate = DateTime.Now;

            _dbContext.SaveChanges();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PostAsync([FromBody] ArtistInputModel value)
        {
            if (value == null)
            {
                return(BadRequest("Invalid input"));
            }

            var result = await _artistsService.AddAsync(value);

            if (result == null)
            {
                return(BadRequest("Artist not inserted"));
            }

            return(CreatedAtRoute("ArtistGetAsync",
                                  new
            {
                id = result.Id
            },
                                  result));
        }
Exemplo n.º 5
0
 public IActionResult UpdateArtist([FromBody] ArtistInputModel artist, int id)
 {
     _artistService.UpdateArtist(id, artist);
     return(NoContent());
 }
Exemplo n.º 6
0
        public IActionResult CreateNewArtist([FromBody] ArtistInputModel artist)
        {
            var newId = _artistService.CreateNewArtist(artist);

            return(CreatedAtRoute("GetArtistById", new { id = newId }, null));
        }
Exemplo n.º 7
0
 public void UpdateArtist(int id, ArtistInputModel artist)
 {
     _artistRepository.UpdateArtist(id, artist);
 }
Exemplo n.º 8
0
 public int CreateNewArtist(ArtistInputModel artist)
 {
     return(_artistRepository.CreateNewArtist(artist));
 }