Ejemplo n.º 1
0
        public IHttpActionResult Update(int id, AlbumModel 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 aircraft does not exists!");
            }

            existingAlbum.Title = album.Title;
            existingAlbum.Year = album.Year;
            existingAlbum.Producer = album.Producer;
            this.data.Songs.SaveChanges();

            return Ok(existingAlbum);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Create(AlbumModel album)
        {
            if (!this.ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            else
            {
                var newAlbum = new Album
                {
                    Title = album.Title,
                    Year = album.Year,
                    Producer = album.Producer,
                };

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

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