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)); } }
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)); }
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 }); } }