Пример #1
0
        //get api/AllSongs?q={searchText}
        protected override string ProcessRequest()
        {
            JavaScriptSerializer json = new JavaScriptSerializer();

            try
            {
                var tableMgr = new TableManager();

                // get query string parameters
                var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query);
                if (string.IsNullOrEmpty(qpParams["q"]))
                {
                    throw new ArgumentException(Constants.API_EXC_SEARCH_TEXT_NOT_EXIST);
                }

                string searchSong = qpParams["q"];

                //get movie list based on song's title
                var movies = tableMgr.SearchSongs(searchSong);  //Collection of movie

                List<Songs> movieSongs = new List<Songs>();

                if (movies != null)
                {
                    // if movie list not null then get each movie's song
                    foreach (var movie in movies)
                    {
                        // deserialize movie songs
                        List<Songs> songs = json.Deserialize(movie.Songs, typeof(Songs)) as List<Songs>;

                        if (songs != null)
                        {
                            foreach (var song in songs)
                            {
                                // add song object to movie songs list
                                movieSongs.Add(song);
                            }
                        }
                    }
                }

                // serialize songs list and then return.
                return json.Serialize(movieSongs);
            }
            catch (Exception ex)
            {
                // if any error occured then return User friendly message with system error message
                return json.Serialize(new { Status = "Error", UserMessage = Constants.UM_WHILE_SEARCHING_SONGS, ActualError = ex.Message });
            }
        }