Ejemplo n.º 1
0
        //GET /Home/Index
        public ActionResult Index(string genre)
        {
            #region Inicijalizacija baza podataka

            DBInitializer initializator = new DBInitializer();
            initializator.Initialize();

            #endregion


            HomePageViewModel pageModel = new HomePageViewModel();

            //Is loged
            if (Session["user"] != null && Session["user"].GetType() == (typeof(ViewUser)))
            {
                pageModel.user = (ViewUser)(Session["user"]);
            }

            Neo4jDataProvider dbNeo4j = new Neo4jDataProvider();
            RedisDataProvider dbRedis = new RedisDataProvider();

            #region NavBarData

            if (genre == "All" || genre == "")
            {
                pageModel.genre = null;
            }
            else
            {
                pageModel.genre = genre;
            }

            //Getting artists
            pageModel.artists = dbNeo4j.ArtistRead(pageModel.genre);
            for (char c = 'A'; c <= 'Z'; c++)
            {
                if (pageModel.artists.ContainsKey(c.ToString()))
                {
                    List <ViewArtist> tmp = pageModel.artists[c.ToString()];
                    pageModel.artists[c.ToString()] = tmp.OrderBy(x => x.name).ToList();
                }
            }


            //Getting genres
            pageModel.genres = dbNeo4j.GenreRead();
            pageModel.genres.Sort();

            #endregion

            //Getting popular songs
            List <string> popularSongNames = dbRedis.GetMostPopularSongs(10);
            pageModel.popularSongs = dbNeo4j.SongRead(popularSongNames);

            //Getting latest songs
            List <string> latestSongNames = dbRedis.GetLatestSongs();
            pageModel.latestSongs = dbNeo4j.SongRead(latestSongNames);

            //Getting songs requests
            pageModel.songRequests = dbNeo4j.SongRequestRead();


            ViewBag.showNav = true;

            return(View(pageModel));
        }