Ejemplo n.º 1
0
        public JsonResult GetSongs(int id)
        {
            // SELECT musicians.name, records.name, rolls.name FROM musiciantorecord
            // JOIN musicians on musiciantorecord.MusicianId = musicians.MusicianId
            // JOIN rolls on musiciantorecord.RollId= rolls.RollId
            // JOIN records on musiciantorecord.RecordId = records.RecordId
            // WHERE musiciantoRecord.recordid = 1;
            System.Console.WriteLine("Searching for record: " + id);
            MySongsView results = new MySongsView();

            List <Song> songsList = _context.Songs.Where(x => x.RecordId == id).ToList();

            if (songsList.Count() > 0)
            {
                System.Console.WriteLine("Success! Found " + songsList.Count() + " songs!");
                // System.Console.WriteLine("Results: " + results.SongNames.Count());

                results.SongNames = InsertionMethods.ExtractSongs(songsList);

                results.Success = true;
                results.Message = "Success! Returned record: " + id;
                System.Console.WriteLine("Success! Returned record: " + id);
            }
            else
            {
                results.Success = false;
                results.Message = "Failure! Returned no songs for record: " + id;
                System.Console.WriteLine("Failure! Returned no songs for record: " + id);
            }

            return(Json(results));
        }
Ejemplo n.º 2
0
        public JsonResult TopSongs(int id)
        {
            // SELECT musicians.name, records.name, rolls.name FROM musiciantorecord
            // JOIN musicians on musiciantorecord.MusicianId = musicians.MusicianId
            // JOIN rolls on musiciantorecord.RollId= rolls.RollId
            // JOIN records on musiciantorecord.RecordId = records.RecordId
            // WHERE musiciantoRecord.recordid = 1;
            System.Console.WriteLine("Searching for record: " + id);
            MySongsView results = new MySongsView();

            List <Song> songsList = _context.Songs.Where(x => x.RecordId == id).ToList();

            if (songsList.Count() > 0)
            {
                System.Console.WriteLine("Success! Found " + songsList.Count() + " songs!");
                System.Console.WriteLine("Results: " + results.SongNames.Count());

                results.SongNames = InsertionMethods.ExtractSongs(songsList);
                results.SongNames = InsertionMethods.WeightSongs(results.SongNames);

                results.SongNames.Sort(
                    delegate(Dictionary <string, string> pair1,
                             Dictionary <string, string> pair2)
                {
                    int parse1 = Int32.Parse(pair1["score"]);
                    int parse2 = Int32.Parse(pair2["score"]);
                    return(parse2.CompareTo(parse1));
                }
                    );

                int i = 0;
                foreach (var song in results.SongNames)
                {
                    results.holisticScore += Int32.Parse(song["holisticscore"]);
                    if (i < 8)
                    {
                        results.weightedScore += Int32.Parse(song["weightedscore"]);
                    }
                    else
                    {
                        i++;
                    }
                }

                results.Success = true;
                results.Message = "Success! Returned record: " + id;
                System.Console.WriteLine("Success! Returned record: " + id);
            }
            else
            {
                results.Success = false;
                results.Message = "Failure! Returned no songs for record: " + id;
                System.Console.WriteLine("Failure! Returned no songs for record: " + id);
            }

            return(Json(results));
        }