public ActionResult ManageAreas(AreaGridModel model)
        {
            if (model.AreaGrid != null)
            {
                return View(model);
            }

            model = new AreaGridModel();
            return View(model);
        }
        public ActionResult SearchAreas(int areaTypeId, string searchText)
        {
            var model = new AreaGridModel {AreaGrid = new List<Area>()};

            HydrateGridFromDBLookup(model, searchText, areaTypeId);

            model.SearchAreaTypeId = areaTypeId;
            model.SearchText = searchText;

            return View("ManageAreas", model);
        }
        private void HydrateGridFromDBLookup(AreaGridModel model, string searchText, int areaTypeId)
        {
            int? areaTypeIdToSearch = null;
            if (areaTypeId > 0)
            {
                areaTypeIdToSearch = areaTypeId;
            }

            IEnumerable<Area> areas = CommonUtilities.GetAreas(searchText, areaTypeIdToSearch);

            PopulateAreaGrid(model, areas);
        }
 private static void PopulateAreaGrid(AreaGridModel model, IEnumerable<Area> areas)
 {
     foreach (Area area in areas)
     {
         model.AreaGrid.Add(new Area
         {
             AreaCode = area.AreaCode,
             AreaName = area.AreaName,
             AreaTypeId = area.AreaTypeId,
             AreaShortName = string.IsNullOrEmpty(area.AreaShortName) ? string.Empty : area.AreaShortName,
             AddressLine1 = string.IsNullOrEmpty(area.AddressLine1) ? string.Empty : area.AddressLine1,
             AddressLine2 = string.IsNullOrEmpty(area.AddressLine2) ? string.Empty : area.AddressLine2,
             AddressLine3 = string.IsNullOrEmpty(area.AddressLine3) ? string.Empty : area.AddressLine3,
             AddressLine4 = string.IsNullOrEmpty(area.AddressLine4) ? string.Empty : area.AddressLine4,
             Postcode = string.IsNullOrEmpty(area.Postcode) ? string.Empty : area.Postcode,
             IsCurrent = area.IsCurrent
         });
     }
 }