public GetArtistMovies ( ) : MovieEntity>.IDictionary |
||
return | MovieEntity>.IDictionary |
// get : api/ArtistMovies?q=artist-name&page={default 30} protected override string ProcessRequest() { const int defaultMoviesCount = 30; int resultLimit = defaultMoviesCount; string artistName = string.Empty; string dataType = string.Empty; // get query string parameters string queryParameters = this.Request.RequestUri.Query; if (queryParameters != null) { var qpParams = HttpUtility.ParseQueryString(queryParameters); if (!string.IsNullOrEmpty(qpParams["page"])) { int.TryParse(qpParams["page"].ToString(), out resultLimit); } if (!string.IsNullOrEmpty(qpParams["name"])) { artistName = qpParams["name"].ToLower().Trim(); } if (!string.IsNullOrEmpty(qpParams["type"])) { dataType = qpParams["type"].ToLower(); } } try { var tableMgr = new TableManager(); if (dataType == "movie") { if (resultLimit == defaultMoviesCount) { string json; string uArtistName = artistName.Replace(" ", "-").Replace(".", "-"); if (!CacheManager.TryGet<string>(CacheConstants.ArtistMoviesJson + uArtistName, out json)) { var moviesByName = tableMgr.GetArtistMovies(artistName); var movies = moviesByName.Take(resultLimit); json = jsonSerializer.Value.Serialize(movies); CacheManager.Add<string>(CacheConstants.ArtistMoviesJson + uArtistName, json); } return json; } else { var moviesByName = tableMgr.GetArtistMovies(artistName); var movies = moviesByName.Take(resultLimit); return jsonSerializer.Value.Serialize(movies); } } else // Bio { string json; string uArtistName = artistName.Replace(" ", "-").Replace(".", "-"); if (!CacheManager.TryGet<string>(CacheConstants.ArtistBioJson + uArtistName, out json)) { json = UpdateArtistHit(uArtistName); CacheManager.Add<string>(CacheConstants.ArtistBioJson + uArtistName, json); } else { Task.Run(() => UpdateArtistHit(uArtistName)); } return json; } } catch (Exception e) { // TODO: Log the error message // if any error occured then return User friendly message with system error message if (dataType == "movie") { return movieError.Value; } else { return bioError.Value; } } }