Beispiel #1
0
        public JsonResult DoesThisCountryExist()
        {
            CountryViewModel ViewModle = new CountryViewModel();
            var countryCount           = 0;

            try
            {
                var resolveRequest = HttpContext.Request;
                resolveRequest.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                string jsonString = new System.IO.StreamReader(resolveRequest.InputStream).ReadToEnd();
                //deserialse
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string countryname = serializer.Deserialize <string>(jsonString);
                using (CountryViewModel presentaion = new CountryViewModel())
                {
                    countryCount = presentaion.GetData()
                                   .Where(x => x.CountryName.ToUpper().Equals(countryname.ToUpper())).Count();
                    return(new JsonResult
                    {
                        Data = new { Data = countryCount, Success = true, ErrorMessage = "" },
                        ContentEncoding = System.Text.Encoding.UTF8,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult
                {
                    Data = new { Data = countryCount, Success = false, ErrorMessage = ex.Message },
                    ContentEncoding = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
Beispiel #2
0
        public JsonResult GetAllCountries(string term)
        {
            /*
             * This is the method used to get all artists for  rebinding
             * */
            var col = new List <CountryViewModel>();

            using (CountryViewModel vm = new CountryViewModel())
            {
                col = (from p in vm.GetData().Take(5)
                       where p.CountryName.ToUpper().Trim().StartsWith(term.ToUpper().Trim())
                       select p
                       ).ToList();

                var retVal = col.Select(c => new { label = c.CountryName, value = c.CountryID });
                return(Json(retVal, JsonRequestBehavior.AllowGet));
            }

            return(Json(col, JsonRequestBehavior.AllowGet));
        }