Ejemplo n.º 1
0
        public IHttpActionResult Create(ArtistModel artist)
        {
            throw new NotImplementedException("I can't add my ArtistModel as an Artist :(");

            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var newArtist = new ArtistModel
            {
                Name = artist.Name
            };

            // How doez I database first?
            //this.data.Artists.Add((Artist)newArtist);
            this.data.Artists.SaveChanges();

            artist.Id = newArtist.Id;
            return Ok(newArtist);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Update(int id, ArtistModel artist)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Artist existingArtist = this.data.Artists.All().FirstOrDefault(a => a.Id == id);

            if (existingArtist == null)
            {
                return BadRequest("The artist does not exist");
            }

            // How doez I database first?
            existingArtist.DateOfBirth = artist.DateOfBirth;
            this.data.Artists.SaveChanges();

            artist.Id = existingArtist.Id;
            return Ok(artist);
        }