public JsonResult Get(string query)
        {
            List <Location>   locations;
            List <LocationVm> records;

            using (AppDB_Context context = new AppDB_Context())
            {
                locations = context.Locations.ToList();

                if (!string.IsNullOrWhiteSpace(query))
                {
                    locations = locations.Where(q => q.Name.Contains(query)).ToList();
                }

                records = locations.Where(l => l.ParentID == null).OrderBy(l => l.OrderNumber)
                          .Select(l => new LocationVm
                {
                    id       = l.ID,
                    text     = l.Name,
                    @checked = l.Checked,
                    //population = l.Population,
                    //flagUrl = l.FlagUrl,
                    children = GetChildren(locations, l.ID)
                }).ToList();
            }

            return(this.Json(records, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveCheckedNodes(List <int> checkedIds)
        {
            if (checkedIds == null)
            {
                checkedIds = new List <int>();
            }
            using (AppDB_Context context = new AppDB_Context())
            {
                var locations = context.Locations.ToList();
                foreach (var location in locations)
                {
                    location.Checked = checkedIds.Contains(location.ID);
                }
                context.SaveChanges();
            }

            return(this.Json(true));
        }