コード例 #1
0
        public JsonResult GetAllLocations(string term)
        {
            /*
             * This is the method used to get all locations for  rebinding
             * */
            var col = new List <CurrentLocationViewModel>();

            using (CurrentLocationViewModel vm = new CurrentLocationViewModel())
            {
                col = (from p in vm.GetData()
                       where p.LocationName.Trim().ToUpper().StartsWith(term.ToUpper().Trim())
                       select p
                       ).ToList();

                var retVal = col.Select(c => new { label = c.LocationName, value = c.LocationID });
                return(Json(retVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        public JsonResult GetAllLocations(string term)
        {
            var col = new List <CurrentLocationViewModel>();

            using (CurrentLocationViewModel location = new CurrentLocationViewModel())
            {
                col = (from p in location.GetData()
                       where p.LocationName.ToUpper().StartsWith(term.ToUpper().Trim())
                       select p
                       ).ToList();

                //converet to item and label
                var retVal = col.Select(c => new { label = c.LocationName, value = c.LocationID });

                return(Json(retVal, JsonRequestBehavior.AllowGet));
            }
            return(Json(col, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public JsonResult DoesLocationExist()
        {
            CurrentLocationViewModel ViewModel = new CurrentLocationViewModel();
            var locationCount = 0;

            try
            {
                //DESERIALIZE
                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 locationName             = serializer.Deserialize <string>(jsonString);
                using (CurrentLocationViewModel presentation = new CurrentLocationViewModel())
                {
                    locationCount = presentation.GetData()
                                    .Where(p => p.LocationName.ToUpper().Trim().StartsWith(locationName.ToUpper().Trim())).Count()
                    ;
                    return(new JsonResult
                    {
                        Data = new { Data = locationCount, Success = true, ErrorMessage = "" },
                        ContentEncoding = System.Text.Encoding.UTF8,
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            catch (Exception ex)
            {
                return(new JsonResult
                {
                    Data = new { Data = locationCount, Success = false, ErrorMessage = ex.Message },
                    ContentEncoding = System.Text.Encoding.UTF8,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }