// get : api/Movies?type={current/all order by name etc} protected override string ProcessRequest() { JavaScriptSerializer json = new JavaScriptSerializer(); try { SetConnectionString(); var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query); if (string.IsNullOrEmpty(qpParams["type"])) { throw new ArgumentException("type is not present"); } string type = qpParams["type"].ToString(); var tableMgr = new TableManager(); var movies = new List<MovieEntity>(); if (type.ToLower() == "orderby") { movies = tableMgr.GetSortedMoviesByName(); } else if (type.ToLower() == "current") { movies = tableMgr.GetCurrentMovies(); } return json.Serialize(movies); } catch (Exception ex) { return json.Serialize(new { Status = "Error", Message = ex.Message }); } }
// get : api/Movies?type={current/all (default)}&resultlimit={default 100} protected override string ProcessRequest() { string type = "all"; int resultLimit = 15; // get query string parameters string queryParameters = this.Request.RequestUri.Query; if (queryParameters != null) { var qpParams = HttpUtility.ParseQueryString(queryParameters); if (!string.IsNullOrEmpty(qpParams["type"])) { type = qpParams["type"].ToString().ToLower(); } if (!string.IsNullOrEmpty(qpParams["resultlimit"])) { int.TryParse(qpParams["resultlimit"].ToString(), out resultLimit); } } try { var tableMgr = new TableManager(); var moviesByName = (type == "all") ? tableMgr.GetSortedMoviesByName() : (type == "current") ? tableMgr.GetCurrentMovies() : (type == "upcoming") ? tableMgr.GetUpcomingMovies() : Enumerable.Empty<MovieEntity>(); List<MovieEntity> movies = moviesByName.Take(resultLimit).ToList(); // serialize movieList object and return. return jsonSerializer.Value.Serialize(movies); } catch (Exception ex) { // if any error occured then return User friendly message with system error message return jsonSerializer.Value.Serialize( new { Status = "Error", UserMessage = "Unable to get " + type + " movies", ActualError = ex.Message }); } }