Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            //cache the results
            if (HttpContext.Current.Cache["personCol"] == null)
            {
                ReferenceServiceClient client = new ReferenceServiceClient();

                HttpContext.Current.Cache["personColCache"] = client.GetAllPersons();
            }

            //get the JSON string which
            //from the UI and convert it to lower case
            //for filtering
            String personName = context.Request.Form[0].ToLower();

            //casting it to our collection
            Collection<Entities.PersonBE> personCol = (Collection<Entities.PersonBE>)HttpContext.Current.Cache["personColCache"];

            //don't do any filtering if char lenght less than two
            //if (personName.Length > 2)
            //{
            personCol = personCol.Where(p => p.name.ToLower().Contains(personName)).ToCollection();
            //}

            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            String jsonString = jsonString = jsSerializer.Serialize(personCol);

            //set the response type to be JSON
            context.Response.ContentType = "application/json; charset=utf-8";

            context.Response.Write(jsonString);
        }