コード例 #1
0
ファイル: Program.cs プロジェクト: Varbanov/TelerikAcademy
        static void Main()
        {
            var ctx = new MusicDbContext();
            MusicData dbContext = new MusicData(ctx);

            for (int i = 0; i < 3; i++)
            {
                var artist = new Artist()
                {
                    Name = "Artist" + i,
                };

                dbContext.Artists.Add(artist);

                var album = new Album() { Title = "Album" + i};
                album.Artists.Add(artist);
                dbContext.Albums.Add(album);

                var song = new Song("Song" + i, artist);
                song.Albums.Add(album);
                dbContext.Songs.Add(song);
            }

            dbContext.SaveChanges();
        }
コード例 #2
0
        public IHttpActionResult Create(ArtistModel artist)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(ModelState);
            }

            var newArtist = new Artist
            {
                Name = artist.Name,
                Country = artist.Country,
                DateOfBirth = artist.DateOfBirth
            };

            this.data.Artists.Add(newArtist);
            this.data.SaveChanges();

            artist.Id = newArtist.Id;
            return this.Ok(newArtist);
        }
コード例 #3
0
ファイル: Song.cs プロジェクト: Varbanov/TelerikAcademy
 public Song(string title, Artist artist)
 {
     this.Title = title;
     this.Artist = artist;
     this.albums = new HashSet<Album>();
 }