Exemplo n.º 1
0
        public IHttpActionResult Create(AlbumModel album)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newAlbum = new Album
            {
                 Title = album.Title
            };

            this.data.Albums.Add(newAlbum);
            this.data.SaveChanges();

            return Ok(newAlbum);
        }
Exemplo n.º 2
0
        public IHttpActionResult Update(int id, Album album)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingAlbum = this.data.Albums.All().FirstOrDefault(a => a.Id == id);
            if (existingAlbum == null)
            {
                return BadRequest("Such album does not exist");
            }

            existingAlbum.Title = album.Title;
            album.Id = existingAlbum.Id;
            this.data.SaveChanges();
            return Ok(album);
        }