示例#1
0
 public ActionResult DeleteTown(RegionViewModel viewModel)
 {
     TownOperationService service = new TownOperationService(townRepository, viewModel);
     bool result = service.DeleteOneTown(eNodebRepository, btsRepository);
     if (result)
     {
         TempData["success"] = viewModel.DeleteSuccessMessage;
     }
     else
     {
         TempData["error"] = viewModel.DeleteFailMessage;
     }
     return RedirectToAction("Region");
 }
 public void TestRegionViewModel_DeleteTownSuccessMessage()
 {
     RegionViewModel viewModel = new RegionViewModel("")
     {
         CityName = "Foshan",
         NewCityName = "Shenzhen",
         DistrictName = "Chancheng",
         NewDistrictName = "Nanhai",
         TownName = "Nanzhuang",
         NewTownName = "Chengqu"
     };
     Assert.AreEqual(viewModel.DeleteSuccessMessage,
         "删除镇街:Foshan-Chancheng-Nanzhuang成功");
 }
示例#3
0
 public ActionResult DeleteRegion(RegionViewModel viewModel)
 {
     RegionOperationService service = new RegionOperationService(regionRepository,
         viewModel.CityName, viewModel.DistrictName, viewModel.RegionName);
     bool result = service.DeleteOneRegion();
     if (result)
     {
         TempData["success"] = viewModel.DeleteRegionSuccessMessage;
     }
     else
     {
         TempData["error"] = viewModel.DeleteRegionFailMessage;
     }
     return RedirectToAction("Region");
 }
 public void TestRegionViewModelAddTownConditions_NewTown()
 {
     RegionViewModel viewModel = new RegionViewModel("")
     {
         CityName = "Foshan",
         NewCityName = "",
         DistrictName = "Chancheng",
         NewDistrictName = "",
         TownName = "Nanzhuang",
         NewTownName = "Chengqu"
     };
     Town town = viewModel.AddTownConditions;
     Assert.AreEqual(town.CityName, "Foshan");
     Assert.AreEqual(town.DistrictName, "Chancheng");
     Assert.AreEqual(town.TownName, "Chengqu");
 }
示例#5
0
 public ActionResult AddTown(RegionViewModel viewModel)
 {
     Town addConditions = viewModel.AddTownConditions;
     if (!addConditions.IsAddConditionsValid())
     {
         TempData["error"] = "输入有误!城市、区域、镇区都不能为空。";
         return RedirectToAction("Region");
     }
     TownOperationService service = new TownOperationService(townRepository, addConditions);
     service.SaveOneTown();
     TempData["success"] = "增加镇街:" + addConditions.GetAddConditionsInfo() + "成功";
     TempData["RegionViewModel"] = new RegionViewModel("addTown")
     {
         CityName = addConditions.CityName,
         DistrictName = addConditions.DistrictName,
         TownName = addConditions.TownName,
         RegionName = viewModel.RegionName
     };
     return RedirectToAction("Region");
 }
 public RegionViewModelInitializeTestHelper(IEnumerable<Town> towns, RegionViewModel viewModel)
 {
     this.towns = towns;
     this.viewModel = viewModel;
     service = new QueryDistinctCityNamesService(towns);
 }
示例#7
0
        public ViewResult Region()
        {
            RegionViewModel viewModel = TempData["RegionViewModel"] as RegionViewModel;
            if (viewModel == null || viewModel.CityName == null)
            {
                List<Town> townList = townRepository.GetAllList();
                Town town = (townList.Count > 0) ? townList.First() : null;

                viewModel = new RegionViewModel("addTown");
                viewModel.InitializeTownList(townRepository, town);
                viewModel.InitializeRegionList(regionRepository, town);
            }
            else
            {
                viewModel.InitializeTownList(townRepository, viewModel);
                viewModel.InitializeRegionList(regionRepository, viewModel);
            }

            return View(viewModel);
        }
示例#8
0
 public ActionResult ModifyRegion(RegionViewModel viewModel)
 {
     RegionOperationService service = new RegionOperationService(regionRepository,
         viewModel.CityName, viewModel.DistrictName, viewModel.RegionName);
     bool result = service.SaveOneRegion(viewModel.ForceSwapRegionDistricts);
     if (result)
     {
         TempData["success"] = viewModel.SaveRegionSuccessMessage;
     }
     else
     {
         TempData["error"] = viewModel.SaveRegionFailMessage;
     }
     TempData["RegionViewModel"] = new RegionViewModel("modifyRegion")
     {
         CityName = viewModel.CityName,
         DistrictName = viewModel.DistrictName,
         TownName = viewModel.TownName,
         RegionName = viewModel.RegionName
     };
     return RedirectToAction("Region");
 }
 private void UpdateServices(RegionViewModel viewModel)
 {
     districtService = new QueryDistinctDistrictNamesService(townRepository.GetAll(), viewModel.CityName);
     townService = new QueryDistinctTownNamesService(townRepository.GetAll(),
         viewModel.CityName, viewModel.DistrictName);
 }
示例#10
0
 private static Town SetAddConditions(int cityId, int districtId, int townId, int newCityId, 
     int newDistrictId, int newTownId, RegionViewModel viewModel)
 {
     if (cityId > 0) { viewModel.CityName = "City" + cityId; }
     if (districtId > 0) { viewModel.DistrictName = "District" + districtId; }
     if (townId > 0) { viewModel.TownName = "Town" + townId; }
     if (newCityId > 0) { viewModel.NewCityName = "City" + newCityId; }
     if (newDistrictId > 0) { viewModel.NewDistrictName = "District" + newDistrictId; }
     if (newTownId > 0) { viewModel.NewTownName = "Town" + newTownId; }
     Town addConditions = viewModel.AddTownConditions;
     return addConditions;
 }
        private void AssertSelectedItems(RegionViewModel viewModel)
        {
            if (towns.FirstOrDefault(x => x.CityName == viewModel.CityName) != null)
            {
                Assert.AreEqual(viewModel.CityList.GetSelectedItemText(), viewModel.CityName);
                Assert.AreEqual(viewModel.CityList.GetSelectedItemValue(), viewModel.CityName);
            }
            else
            {
                Assert.IsNull(viewModel.CityList.GetSelectedItemText());
                Assert.IsNull(viewModel.CityList.GetSelectedItemValue());
            }

            if (towns.FirstOrDefault(x => x.CityName == viewModel.CityName
                && x.DistrictName == viewModel.DistrictName) != null)
            {
                Assert.AreEqual(viewModel.DistrictList.GetSelectedItemText(), viewModel.DistrictName);
                Assert.AreEqual(viewModel.DistrictList.GetSelectedItemValue(), viewModel.DistrictName);
            }
            else
            {
                Assert.IsNull(viewModel.DistrictList.GetSelectedItemText());
                Assert.IsNull(viewModel.DistrictList.GetSelectedItemValue());
            }

            if (towns.Query(viewModel) != null)
            {
                Assert.AreEqual(viewModel.TownList.GetSelectedItemText(), viewModel.TownName);
                Assert.AreEqual(viewModel.TownList.GetSelectedItemValue(), viewModel.TownName);
            }
            else
            {
                Assert.IsNull(viewModel.TownList.GetSelectedItemText());
                Assert.IsNull(viewModel.TownList.GetSelectedItemValue());
            }
        }
 private void AssertNames(RegionViewModel initialViewModel, RegionViewModel viewModel)
 {
     if (initialViewModel == null)
     {
         Assert.AreEqual(viewModel.CityName, towns.ElementAt(0).CityName);
         Assert.AreEqual(viewModel.DistrictName, towns.ElementAt(0).DistrictName);
         Assert.AreEqual(viewModel.TownName, towns.ElementAt(0).TownName);
     }
     else
     {
         Assert.AreEqual(viewModel.CityName, initialViewModel.CityName);
         Assert.AreEqual(viewModel.DistrictName, initialViewModel.DistrictName);
         Assert.AreEqual(viewModel.TownName, initialViewModel.TownName);
     }
 }