Example #1
0
        public static MvcHtmlString AlbumTitle(this HtmlHelper helper,Album album)
        {
            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
            var container = new TagBuilder("div");
            var albumTitle = new TagBuilder("a");
            var artistTitle = new TagBuilder("a");
            albumTitle.MergeAttribute("href", urlHelper.Action("Detail", "Album", new { id = album.Id }));
            albumTitle.MergeAttribute("class", "list-item-AlbumTitle");
            albumTitle.SetInnerText(album.Name);
            artistTitle.MergeAttribute("href", urlHelper.Action("Albums", "Artist", new { id = album.Artist.Id }));
            artistTitle.SetInnerText(album.Artist.Name);

            container.InnerHtml = albumTitle.ToString() + " by " + artistTitle.ToString();
            return MvcHtmlString.Create(container.ToString());
        }
Example #2
0
 private void RemoveSongs(Album oldAlbum, IEnumerable<Song> newSongs)
 {
     var removeIds = new List<int>();
     foreach (var oldSong in oldAlbum.Songs)
     {
         var newSong = newSongs.FirstOrDefault(song => song.Id == oldSong.Id);
         if (newSong == null)
         {
             var dbSong = db.Songs.FirstOrDefault(song => song.Id == oldSong.Id);
             if (dbSong != null)
             {
                 removeIds.Add(oldSong.Id);
             }
         }
     }
     removeIds.ForEach(id => db.Songs.Remove(db.Songs.Find(id)));
 }
Example #3
0
 private void UpdateSongs(Album oldAlbum,IEnumerable<Song> newSongs)
 {
     foreach (var oldSong in oldAlbum.Songs)
     {
         var newSong = newSongs.FirstOrDefault(song => song.Id == oldSong.Id);
         if (newSong != null)
         {
             oldSong.Name = newSong.Name;
             oldSong.Length = newSong.Length;
             oldSong.SongNumber = newSong.SongNumber;
         }
     }
     RemoveSongs(oldAlbum, newSongs);
     InsertNewSongs(oldAlbum, newSongs);
 }
Example #4
0
 private void InsertNewSongs(Album oldAlbum,IEnumerable<Song> newSongs)
 {
     foreach (var newSong in newSongs)
     {
         if (newSong.Id<=0 || !oldAlbum.Songs.Any(oldSong => oldSong.Id == newSong.Id))
         {
             oldAlbum.Songs.Add(newSong);
         }
     }
 }