// POST /artists
        public IHttpActionResult PostArtist(Artist artist)
        {
            // TODO artist name must be unique
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            _db.Artists.Add(artist);
            _db.SaveChanges();
            return CreatedAtRoute("DefaultApi", new {id = artist.ArtistId}, artist);
        }
        public IHttpActionResult PutArtist(int id, Artist artist)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != artist.ArtistId)
            {
                return BadRequest();
            }

            _db.Entry(artist).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemple #3
0
 public Album(Artist artist, string name)
     : this()
 {
     Artist = artist;
     Name = name;
 }