Exemplo n.º 1
0
        // get : api/Actor?n={actor/actress/producer...etc name}
        protected override string ProcessRequest()
        {
            JavaScriptSerializer json = new JavaScriptSerializer();

            try
            {
                var tableMgr = new TableManager();

                // get query string parameters
                var qpParam = HttpUtility.ParseQueryString(this.Request.RequestUri.Query);

                if (string.IsNullOrEmpty(qpParam["n"]))
                {
                    throw new ArgumentException(Constants.API_EXC_SEARCH_TEXT_NOT_EXIST);
                }

                string actorName = qpParam["n"].ToString();

                // get movies by actor(roles like actor, actress, producer, director... etc)
                var movies = tableMgr.SearchMoviesByActor(actorName);

                // serialize movie list and return
                return json.Serialize(movies);
            }
            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_MOVIES, ActualError = ex.Message });
            }
        }
Exemplo n.º 2
0
        //Give the all unique actor name.
        protected override string ProcessRequest()
        {
            JavaScriptSerializer json = new JavaScriptSerializer();
            try
            {
                var tblMgr = new TableManager();

                //var movies = tblMgr.GetAllMovies();
                 var qpParam = HttpUtility.ParseQueryString(this.Request.RequestUri.Query);

                if (string.IsNullOrEmpty(qpParam["query"]))
                {
                    throw new ArgumentException(Constants.API_EXC_SEARCH_TEXT_NOT_EXIST);
                }

                string actorName = qpParam["query"].ToString();

                // get movies by actor(roles like actor, actress, producer, director... etc)
                var movies = tblMgr.SearchMoviesByActor(actorName);

                List<Object> allCast = new List<Object>();
                List<Cast> tempCast = new List<Cast>();
                int counter = 0;
                foreach (var movie in movies)
                {
                    List<Cast> castList = json.Deserialize(movie.Cast, typeof(List<Cast>)) as List<Cast>;
                    if (castList != null)
                    {

                        foreach (var cast in castList)
                        {
                            if (!tempCast.Exists(c => c.name == cast.name))
                            {
                                tempCast.Add(cast);
                                allCast.Add(new { id = ++counter, name = cast.name });
                            }
                        }

                    }
                }
                return json.Serialize(allCast);
            }
            catch (Exception ex)
            {
                return json.Serialize(new { staus = "Error", UserMessage = Constants.UM_WHILE_GETTING_CURRENT_MOVIES, ActualError = ex.Message });
                //throw new ArgumentException();
            }
        }