コード例 #1
0
        public string Get()
        {
            Console.WriteLine("Get all songs.");

            StateOfRequest mState = new StateOfRequest("SongNo");

            mState.CurrentPageNo = 1;
            mState.PageSize      = 50;

            // List<Song> songs = await _songsManager.GetAllSongs(mState);
            // get the first 50 songs
            List <Song> songs = _songsManager.GetOnePageOfSongs(mState);

            JObject jObjectForAll = new JObject();

            jObjectForAll.Add("pageNo", mState.CurrentPageNo);
            jObjectForAll.Add("pageSize", mState.PageSize);
            jObjectForAll.Add("totalRecords", mState.TotalRecords);
            jObjectForAll.Add("totalPages", mState.TotalPages);
            JObject jObject;
            JArray  jArray = new JArray();

            for (int i = 0; i < songs.Count; i++)
            {
                Song song = songs[i];
                jObject = JsonUtil.ConvertSongToJsongObject(song);
                jArray.Add(jObject);
            }
            jObjectForAll.Add("songs", jArray);

            return(jObjectForAll.ToString());
        }
コード例 #2
0
        public async Task <string> Get(int id)
        {
            // get one song
            Song song = await _songsManager.FindOneSongById(id);

            JObject jObject    = JsonUtil.ConvertSongToJsongObject(song);
            JObject returnJSON = new JObject();

            returnJSON.Add("song", jObject);

            return(returnJSON.ToString());
        }
コード例 #3
0
        private JObject GetSongsBySingerId(int id, int pageSize, int pageNo, string orderBy, string filter)
        {
            string orderByParam;

            if (string.IsNullOrEmpty(orderBy))
            {
                orderByParam = "";
            }
            else
            {
                orderByParam = orderBy.Trim();
            }
            string filterParam;

            if (string.IsNullOrEmpty(filter))
            {
                filterParam = "";
            }
            else
            {
                filterParam = filter.Trim();
            }

            StateOfRequest mState = new StateOfRequest(orderByParam);

            mState.PageSize       = pageSize;
            mState.CurrentPageNo  = pageNo;
            mState.QueryCondition = filterParam;

            List <Song> songs = _songsManager.GetOnePageOfSongsBySingerId(mState, id, true);

            JObject jObjectForAll = new JObject();

            jObjectForAll.Add("pageNo", mState.CurrentPageNo);
            jObjectForAll.Add("pageSize", mState.PageSize);
            jObjectForAll.Add("totalRecords", mState.TotalRecords);
            jObjectForAll.Add("totalPages", mState.TotalPages);
            JObject jObject;
            JArray  jArray = new JArray();

            foreach (var song in songs)
            {
                jObject = JsonUtil.ConvertSongToJsongObject(song);
                jArray.Add(jObject);
            }
            jObjectForAll.Add("songs", jArray);

            return(jObjectForAll);
        }
コード例 #4
0
        private JObject GetSongsByLanguageIdAndSomething(int id, int numOfWords, int pageSize, int pageNo, string orderBy, int songType, String filter)
        {
            string orderByParam;

            if (string.IsNullOrEmpty(orderBy))
            {
                orderByParam = "";
            }
            else
            {
                orderByParam = orderBy.Trim();
            }
            string filterParam;

            if (string.IsNullOrEmpty(filter))
            {
                filterParam = "";
            }
            else
            {
                filterParam = filter.Trim();
            }

            StateOfRequest mState = new StateOfRequest(orderByParam);

            mState.PageSize       = pageSize;
            mState.CurrentPageNo  = pageNo;
            mState.QueryCondition = filterParam;

            List <Song> songs = new List <Song>();

            switch (songType)
            {
            case Normal_SongType:
                // normal
                songs = _songsManager.GetOnePageOfSongsByLanguageIdNumOfWords(mState, id, numOfWords, true);
                break;

            case NewSong_SongType:
                // new songs
                songs = _songsManager.GetOnePageOfNewSongByLanguageId(mState, id, true);
                break;

            case HotSong_SongType:
                // hot songs
                songs = _songsManager.GetOnePageOfHotSongByLanguageId(mState, id, true);
                break;

            default:
                break;
            }

            JObject jObjectForAll = new JObject();

            jObjectForAll.Add("pageNo", mState.CurrentPageNo);
            jObjectForAll.Add("pageSize", mState.PageSize);
            jObjectForAll.Add("totalRecords", mState.TotalRecords);
            jObjectForAll.Add("totalPages", mState.TotalPages);
            JObject jObject;
            JArray  jArray = new JArray();

            foreach (var song in songs)
            {
                jObject = JsonUtil.ConvertSongToJsongObject(song);
                jArray.Add(jObject);
            }
            jObjectForAll.Add("songs", jArray);

            return(jObjectForAll);
        }