//
        // GET: /MemberZone/Edit/By ID

        public ActionResult Edit(int id)
        {
            try
            {
                var memberZone = _db.MemberZones.Find(id);
                if (memberZone != null)
                {
                    var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName", isEdit: true, selectedValue: memberZone != null ? memberZone.MemberDistrictId.ToString() : "0").ToList();

                    var memberZoneViewModel = new MemberZoneViewModel {
                        Id = memberZone.Id, ZoneName = memberZone.ZoneName, LocationX = memberZone.LocationX, LocationY = memberZone.LocationY, MemberDistrictId = memberZone.MemberDistrictId, ddlMemberDistricts = memberDistricts
                    };

                    return(PartialView("_Edit", memberZoneViewModel));
                }
                else
                {
                    return(RedirectToAction("Index", "MemberZone"));
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return(RedirectToAction("Index", "MemberZone"));
            }
        }
        //ZoneInfo
        public ActionResult ZoneInfo(int id)
        {
            var memberZone = _db.MemberZones.Find(id);

            var memberZoneViewModel = new MemberZoneViewModel {
                Id = memberZone.Id, ZoneName = memberZone.ZoneName
            };

            return(View(memberZoneViewModel));
        }
        //ZoneDetails
        public ActionResult ZoneDetails(string id)
        {
            var memberZone = _db.MemberZones.ToList().SingleOrDefault(x => x.ZoneName == id);

            var memberZoneViewModel = new MemberZoneViewModel();

            if (memberZone != null)
            {
                memberZoneViewModel = new MemberZoneViewModel {
                    Id = memberZone.Id, ZoneName = memberZone.ZoneName
                };

                return(View(memberZoneViewModel));
            }
            return(View(memberZoneViewModel));
        }
        //
        // GET: /MemberZone/Add

        public ActionResult Add()
        {
            try
            {
                var memberDistricts = SelectListItemExtension.PopulateDropdownList(_db.MemberDistricts.ToList <MemberDistrict>(), "Id", "DistrictName").ToList();

                var memberZoneViewModel = new MemberZoneViewModel {
                    ddlMemberDistricts = memberDistricts
                };

                return(PartialView("_Add", memberZoneViewModel));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return(RedirectToAction("Index", "MemberZone"));
            }
        }
        //
        // GET: /MemberZone/Details/By ID

        public ActionResult Details(int id)
        {
            try
            {
                var memberZone = _db.MemberZones.Find(id);
                if (memberZone != null)
                {
                    var memberZoneViewModel = new MemberZoneViewModel {
                        Id = memberZone.Id, ZoneName = memberZone.ZoneName, LocationX = memberZone.LocationX, LocationY = memberZone.LocationY, MemberDistrictId = memberZone.MemberDistrictId, MemberDistrictName = memberZone.MemberDistrict != null ? memberZone.MemberDistrict.DistrictName : null
                    };

                    return(PartialView("_Details", memberZoneViewModel));
                }
                else
                {
                    return(RedirectToAction("Index", "MemberZone"));
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return(RedirectToAction("Index", "MemberZone"));
            }
        }
        public ActionResult Edit(MemberZoneViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var memberZone = new MemberZone {
                        Id = viewModel.Id, ZoneName = viewModel.ZoneName, LocationX = viewModel.LocationX, LocationY = viewModel.LocationY, MemberDistrictId = viewModel.MemberDistrictId
                    };

                    _db.Entry(memberZone).State = EntityState.Modified;
                    _db.SaveChanges();

                    return(Content(Boolean.TrueString));
                }

                return(Content(ExceptionHelper.ModelStateErrorFormat(ModelState)));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return(Content("Sorry! Unable to edit this member zone."));
            }
        }