public ActionResult Create(int typeid)
 {
     var model = new AdminUnitModel();
     switch (typeid)
     {
         case 2:
             model.SelectedAdminUnitTypeId = Shared.Configuration.RegionTypeId;
             return PartialView("CreateRegion", model);
         case 3:
             model.SelectedAdminUnitTypeId = Shared.Configuration.ZoneTypeId;
             return PartialView("CreateZone", model);
         case 4:
             model.SelectedAdminUnitTypeId = Shared.Configuration.WoredaTypeId;
             return View("CreateWoreda", model);
         default:
             model.SelectedAdminUnitTypeId = Shared.Configuration.RegionTypeId;
             return PartialView("CreateRegion", model);
     }
 }
        public void CanViewCreate()
        {
            //ACT
            var adminUnitModel = new AdminUnitModel { UnitName = "W. Arsi" };
            var jsonResult = _adminUnitController.Create(adminUnitModel) as JsonResult;

            //ASSERT
            Assert.IsNotNull(jsonResult);
            dynamic data = jsonResult.Data;
            Assert.AreEqual(true, data.success);
        }
        public ActionResult Create(AdminUnitModel unit)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var aunit = new AdminUnit {AdminUnitTypeID = unit.SelectedAdminUnitTypeId};
                    if (aunit.AdminUnitTypeID == Shared.Configuration.ZoneTypeId)
                    {
                        aunit.ParentID = unit.SelectedRegionId;
                    }
                    else if (aunit.AdminUnitTypeID == Shared.Configuration.WoredaTypeId)
                    {
                        aunit.ParentID = unit.SelectedZoneId;
                    }
                    aunit.Name = unit.UnitName;
                    aunit.NameAM = unit.UnitNameAM;

                    _adminUnitService.AddAdminUnit(aunit);
                    return Json(new {success = true});
                }
                catch (Exception)
                {
                    return View();
                }
            }
            return View("Create");
        }
 public ActionResult CreateZone(int? regionId)
 {
     var model = new AdminUnitModel();
     if (regionId.HasValue)
     {
         var region = _adminUnitService.FindById(regionId.Value);
         model.SelectedRegionId = region.AdminUnitID;
         model.SelectedRegionName = region.Name;
     }
     model.SelectedAdminUnitTypeId = Shared.Configuration.ZoneTypeId;
     return PartialView("CreateZone", model);
 }
        public ActionResult CreateWoreda(int? zoneId)
        {
            var model = new AdminUnitModel {SelectedAdminUnitTypeId = Shared.Configuration.WoredaTypeId};

            if (zoneId.HasValue)
            {
                var zone = _adminUnitService.FindById(zoneId.Value);
                model.SelectedZoneName = zone.Name;
                model.SelectedZoneId = zone.AdminUnitID;
                model.SelectedRegionId = zone.AdminUnit2.AdminUnitID;
                model.SelectedRegionName = zone.AdminUnit2.Name;
            }
            return PartialView("CreateWoreda", model);
        }
 public ActionResult CreateRegion()
 {
     var model = new AdminUnitModel {SelectedAdminUnitTypeId = Shared.Configuration.RegionTypeId};
     return PartialView("CreateRegion", model);
 }
 public void AdminUnits_Create_Positive_Post_Test()
 {
     AdminUnitModel unit = new AdminUnitModel();
     mockRepository.Setup(p => p.AdminUnit.Add(new BLL.AdminUnit())).Verifiable();
     AdminUnitController target = new AdminUnitController(mockRepository.Object);
     JsonResult expected = new JsonResult();
     expected.Data = new { success = true };
     //string expected = "{ success = true }";
     JsonResult actual;
     actual = (JsonResult)target.Create(unit);
     Assert.IsNotNull(actual.Data);
     Assert.AreEqual(expected.Data.ToString(), actual.Data.ToString());
 }
 public void AdminUnits_Create_Negative_Post_Test()
 {
     mockRepository.Setup(p => p.AdminUnit.Add(new BLL.AdminUnit())).Verifiable();
     AdminUnitController target = new AdminUnitController(mockRepository.Object); // TODO: Initialize to an appropriate value
     AdminUnitModel unit = new AdminUnitModel(); // TODO: Initialize to an appropriate value
     base.SetModelError(target);
     string viewName = "Create";
     ViewResult actual;
     actual = (ViewResult)target.Create(unit);
     Assert.IsNotNull(actual);
     Assert.AreEqual(viewName, actual.ViewName);
 }
Exemplo n.º 9
0
        private void PrepareFDPForEdit(int? fdpid)
        {
            var unitModel = new AdminUnitModel();
            var fdp = fdpid != null ? _fdpService.FindById(fdpid.Value) : null;
            if (fdp != null)
            {
                unitModel.SelectedWoredaId = fdp.AdminUnitID;
                if (fdp.AdminUnit.ParentID != null) unitModel.SelectedZoneId = fdp.AdminUnit.ParentID.Value;

                unitModel.SelectedRegionId = _adminUnitService.GetRegionByZoneId(unitModel.SelectedZoneId);
                ViewBag.SelectedRegionId = new SelectList(_adminUnitService.GetRegions().Select(p => new { Id = p.AdminUnitID, p.Name}).OrderBy(o => o.Name), "Id", "Name", unitModel.SelectedRegionId);
                ViewBag.SelectedZoneId = new SelectList(GetChildren(unitModel.SelectedRegionId).OrderBy(o => o.Name), "Id", "Name", unitModel.SelectedZoneId);
                ViewBag.SelectedWoredaId = new SelectList(GetChildren(unitModel.SelectedZoneId).OrderBy(o => o.Name), "Id", "Name", unitModel.SelectedWoredaId);
                ViewBag.FDPID = new SelectList(GetFdps(unitModel.SelectedWoredaId).OrderBy(o => o.Name), "Id", "Name", fdp.FDPID);
            }
            else
            {
                ViewBag.SelectedRegionId = new SelectList(unitModel.Regions, "Id", "Name");
                ViewBag.SelectedWoredaId = new SelectList(Enumerable.Empty<SelectListItem>(), "Id", "Name");
                ViewBag.FDPID = new SelectList(Enumerable.Empty<SelectListItem>(), "Id", "Name");
                ViewBag.SelectedZoneId = new SelectList(Enumerable.Empty<SelectListItem>(), "Id", "Name");
            }
        }