private Woreda GetWoreda(WoredaViewModel woredaViewModel)
        {
            var woreda = new Woreda
            {
                WoredaName = woredaViewModel.WoredaName,
                SubcityId  = woredaViewModel.SubcityId
            };

            return(woreda);
        }
        public WoredaViewModel GetWoredaViewModel(Woreda woreda)
        {
            var woredaViewModel = new WoredaViewModel
            {
                WoredaId    = woreda.WoredaId,
                WoredaName  = woreda.WoredaName,
                SubcityId   = woreda.SubcityId,
                SubcityName = woreda.Subcity.SubcityName
            };

            return(woredaViewModel);
        }
        public ActionResult Create([Bind(Include = "WoredaId,SubcityId,WoredaName")] WoredaViewModel woredaViewModel)
        {
            var woreda = GetWoreda(woredaViewModel);

            woreda.WoredaId = Guid.NewGuid();
            if (ModelState.IsValid)
            {
                woredaService.InsertWoreda(woreda);
                return(RedirectToAction("Index"));
            }

            ViewBag.SubcityId = new SelectList(subcityService.GeSubcities(), "SubcityId", "SubcityName", woreda.SubcityId);
            return(View(GetWoredaViewModel(woreda)));
        }
        public ActionResult Edit([Bind(Include = "WoredaId,SubcityId,WoredaName,SubcityName")] WoredaViewModel woredaViewModel)
        {
            var woreda = woredaService.GetWoreda(woredaViewModel.WoredaId);

            woreda.SubcityId  = woredaViewModel.SubcityId;
            woreda.WoredaName = woredaViewModel.WoredaName;

            if (ModelState.IsValid)
            {
                woredaService.UpdateWoreda(woreda);
                return(RedirectToAction("Index"));
            }
            ViewBag.SubcityId = new SelectList(subcityService.GeSubcities(), "SubcityId", "SubcityName", woreda.SubcityId);
            return(View(GetWoredaViewModel(woreda)));
        }
        private IEnumerable <ZonesViewModel> BindZoneViewModel(IEnumerable <AdminUnit> zones)
        {
            var zoneViewModels = new List <ZonesViewModel>();

            foreach (var zone in zones)
            {
                var zoneViewModel = new ZonesViewModel();
                zoneViewModel.AdminUnitID = zone.AdminUnitID;
                zoneViewModel.Zone        = zone.Name;
                foreach (var woreda in zone.AdminUnit1)
                {
                    var woredaViewModel = new WoredaViewModel {
                        Woreda = woreda.Name, AdminUnitID = woreda.AdminUnitID
                    };
                    var woreda1      = woreda;
                    var fdpsInWoreda = _fdpService.Get(t => t.AdminUnitID == woreda1.AdminUnitID, null, "AdminUnit").ToList();
                    woredaViewModel.FDPs = BindFDPViewModel(fdpsInWoreda);
                    zoneViewModel.Woredas.Add(woredaViewModel);
                }
                zoneViewModels.Add(zoneViewModel);
            }
            return(zoneViewModels);
        }