Example #1
0
        // GET: Compositions/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var composition = await _context.Composition
                              .Include(c => c.Album.AlbumsArtists)
                              .ThenInclude(ga => ga.Artist)
                              .Include(c => c.Song)
                              .FirstOrDefaultAsync(m => m.CompositionId == id);

            if (composition == null)
            {
                return(NotFound());
            }
            CompositionViewModel compositionView = new CompositionViewModel();

            if (User.Identity.IsAuthenticated)
            {
                var currentUserId = new Guid(User.FindFirst(x => x.Type == "id").Value);
                compositionView = ViewModelConstructor.FavouriteSongs(new List <Composition> {
                    composition
                }, _context, currentUserId).First();
            }
            else
            {
                compositionView.Composition = composition;
            }

            return(View(compositionView));
        }
Example #2
0
        // GET: MixTapes/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var mixTape = await _context.MixTape
                          .FirstOrDefaultAsync(m => m.MixTapeId == id);

            if (mixTape == null)
            {
                return(NotFound());
            }

            var compositions = await _context.MixtapesCompositions
                               .Where(mc => mc.MixTapeId == id)
                               .Join
                               (
                _context.Composition
                .Include(c => c.Album.AlbumsArtists)
                .ThenInclude(ga => ga.Artist)
                .Include(c => c.Song),
                mc => mc.CompositionId,
                c => c.CompositionId,
                (mc, c) => new { mc, c }
                               )
                               .Select(mcc => mcc.c)
                               .ToListAsync();

            MixTapeViewModel mixTapeView = new MixTapeViewModel();

            mixTapeView.MixTape = mixTape;
            if (User.Identity.IsAuthenticated)
            {
                var currentUserId = new Guid(User.FindFirst(x => x.Type == "id").Value);
                mixTapeView.Compositions = ViewModelConstructor.FavouriteSongs(compositions, _context, currentUserId);
            }
            else
            {
                foreach (var comp in compositions)
                {
                    var compVM = new CompositionViewModel()
                    {
                        Composition = comp
                    };
                    mixTapeView.Compositions.Add(compVM);
                }
            }


            return(View(mixTapeView));
        }
Example #3
0
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound("id == null"));
            }

            var user = await _context.User
                       .Include(u => u.Role)
                       .Include(u => u.FavouriteSongs)
                       .ThenInclude(fs => fs.Composition.Album.AlbumsArtists)
                       .ThenInclude(ga => ga.Artist)
                       .Include(u => u.FavouriteSongs)
                       .ThenInclude(fs => fs.Composition.Song)
                       .Include(u => u.FavouriteArtists)
                       .ThenInclude(fa => fa.Artist)
                       .ThenInclude(a => a.AlbumsArtists)
                       .ThenInclude(g => g.Album)
                       .Include(u => u.LoadedSongs)
                       .ThenInclude(ls => ls.Composition.Song)
                       .FirstOrDefaultAsync(u => u.UserId == id);

            if (user == null)
            {
                return(NotFound("user == null"));
            }
            var userVM = new UserViewModel()
            {
                User = user
            };
            var compositionsF = new List <Composition>();

            foreach (var song in user.FavouriteSongs)
            {
                compositionsF.Add(song.Composition);
            }
            Guid currentUserId = new Guid(User.FindFirst(x => x.Type == "id").Value);

            userVM.FavouriteCompositions = ViewModelConstructor.FavouriteSongs(compositionsF, _context, currentUserId);
            var artistsF = new List <Artist>();

            foreach (var artist in user.FavouriteArtists)
            {
                artistsF.Add(artist.Artist);
            }
            userVM.FavouriteArtists = ViewModelConstructor.FavouriteArtists(artistsF, _context, currentUserId);
            userVM.LoadedSongs      = user.LoadedSongs.ToList();
            return(View(userVM));
        }
Example #4
0
        public async Task <IActionResult> Index()
        {
            var compositions = from c in _context.Composition
                               .Include(c => c.Album.AlbumsArtists)
                               .ThenInclude(c => c.Artist)
                               .Include(c => c.Song)
                               .OrderByDescending(c => c.FavouriteSongs.Count)
                               .Take(10)
                               select c;
            var albums = from c in _context.Album
                         .Include(c => c.AlbumsArtists)
                         .ThenInclude(c => c.Artist)
                         .OrderByDescending(c => c.Date)
                         .Take(10)
                         select c;

            var compositionsF = await compositions.ToListAsync();

            var home = new HomeModel
            {
                Albums = await albums.ToListAsync(),
            };

            if (User.Identity.IsAuthenticated)
            {
                var userId = new Guid(User.FindFirst(x => x.Type == "id").Value);
                home.Compositions = ViewModelConstructor.FavouriteSongs(compositionsF, _context, userId);
            }
            else
            {
                foreach (var comp in compositionsF)
                {
                    var compVM = new CompositionViewModel()
                    {
                        Composition = comp
                    };
                    home.Compositions.Add(compVM);
                }
            }
            //var userId = new Guid(User.FindFirst(x => x.Type == "id").Value);
            //home.Compositions = ViewModelConstructor.FavouriteSongs(compositionsF, _context, userId);

            return(View(home));
        }
Example #5
0
        // GET: Albums/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var album = await _context.Album
                        .Include(a => a.Genre)
                        .Include(a => a.AlbumsArtists)
                        .ThenInclude(a => a.Artist)
                        .Include(a => a.Composition)
                        .ThenInclude(c => c.Song)
                        .FirstOrDefaultAsync(m => m.AlbumId == id);

            if (album == null)
            {
                return(NotFound());
            }
            AlbumViewModel albumView = new AlbumViewModel();

            if (User.Identity.IsAuthenticated)
            {
                var currentUserId = new Guid(User.FindFirst(x => x.Type == "id").Value);
                albumView.Compositions = ViewModelConstructor.FavouriteSongs(album.Composition.ToList(), _context, currentUserId);
            }
            else
            {
                foreach (var comp in album.Composition.ToList())
                {
                    var compVM = new CompositionViewModel()
                    {
                        Composition = comp
                    };
                    albumView.Compositions.Add(compVM);
                }
            }
            albumView.Album = album;


            return(View(albumView));
        }
Example #6
0
        // GET: SearchResults
        public async Task <IActionResult> Index(string searchString)
        {
            var search       = new SearchModel();
            var compositions = from c in _context.Composition
                               .Include(c => c.Album.AlbumsArtists)
                               .ThenInclude(c => c.Artist)
                               .Include(c => c.Song)
                               select c;

            if (!String.IsNullOrEmpty(searchString))
            {
                compositions = compositions.Where(s => s.Song.Title.Contains(searchString));
            }
            var compositionsF = await compositions.ToListAsync();

            if (User.Identity.IsAuthenticated)
            {
                var userId = new Guid(User.FindFirst(x => x.Type == "id").Value);
                search.Compositions = ViewModelConstructor.FavouriteSongs(compositionsF, _context, userId);
            }
            else
            {
                foreach (var comp in compositionsF)
                {
                    var compVM = new CompositionViewModel()
                    {
                        Composition = comp
                    };
                    search.Compositions.Add(compVM);
                }
            }
            var artists = from c in _context.Artist
                          .Include(c => c.AlbumsArtists)
                          .ThenInclude(c => c.Album)
                          .ThenInclude(c => c.Genre)
                          select c;

            if (!String.IsNullOrEmpty(searchString))
            {
                artists = artists.Where(s => s.Name.Contains(searchString));
            }
            var artistsF = await artists.ToListAsync();

            if (User.Identity.IsAuthenticated)
            {
                var userId = new Guid(User.FindFirst(x => x.Type == "id").Value);
                search.Artists = ViewModelConstructor.FavouriteArtists(artistsF, _context, userId);
            }
            else
            {
                foreach (var art in artistsF)
                {
                    var artVM = new ArtistsViewModel()
                    {
                        Artist = art
                    };
                    search.Artists.Add(artVM);
                }
            }

            var albums = from c in _context.Album
                         .Include(c => c.AlbumsArtists)
                         .ThenInclude(c => c.Artist)
                         select c;

            if (!String.IsNullOrEmpty(searchString))
            {
                albums = albums.Where(s => s.Title.Contains(searchString));
            }
            search.Albums = await albums.ToListAsync();

            var mixTapes = from c in _context.MixTape
                           select c;

            if (!String.IsNullOrEmpty(searchString))
            {
                mixTapes = mixTapes.Where(s => s.Title.Contains(searchString));
            }
            search.MixTapes = await mixTapes.ToListAsync();

            return(View(search));
        }