Exemplo n.º 1
0
        public IHttpActionResult Update(int id, ArtistModel artist)
        {
            var existingArtist = this.data.Artist.SelectAll().FirstOrDefault(a => a.Id == id);

            if (existingArtist == null)
            {
                return BadRequest("No such artist with this id!");
            }

            existingArtist.Name = (artist.Name != null) ? artist.Name : existingArtist.Name;
            existingArtist.Country = (artist.Country != null) ? artist.Country : existingArtist.Country;
            existingArtist.DateOfBirth = (artist.DateOfBirth.Date == default(DateTime)) ? existingArtist.DateOfBirth : artist.DateOfBirth;

            this.data.Artist.Update(existingArtist);
            this.data.SaveChanges();

            return Ok(HttpStatusCode.OK);
        }
Exemplo n.º 2
0
        public IHttpActionResult Create(ArtistModel artist)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            this.data.Artist.Add(new Artist
            {
                Name = artist.Name,
                Country = artist.Country,
                DateOfBirth = artist.DateOfBirth

            });

            this.data.SaveChanges();

            return Ok(HttpStatusCode.Created);
        }