Пример #1
0
        public IHttpActionResult Create(AlbumModel album)
        {
            throw new NotImplementedException("I can't add my AlbumModel as an Album :(");

            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var newAlbun = new AlbumModel
            {
                Title=album.Title
            };

            // How doez I database first?
            //this.data.Albums.Add((Album)newAlbun);
            this.data.Albums.SaveChanges();

            album.Id = newAlbun.Id;
            return Ok(newAlbun);
        }
Пример #2
0
        public IHttpActionResult Update(int id, AlbumModel album)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Album existingAlbum = this.data.Albums.All().FirstOrDefault(a => a.Id == id);

            if (existingAlbum == null)
            {
                return BadRequest("The album does not exist");
            }

            // How doez I database first?
            existingAlbum.Year = album.Year;
            this.data.Albums.SaveChanges();

            album.Id = existingAlbum.Id;
            return Ok(album);
        }