public ActionResult Create(PropertyInsertView property) { if (ModelState.IsValid) { if (!PhoneExist(property.PhoneNumber)) { Property p = new Property(); Block block = uow.BlockRepository.GetByID(property.BlockId); p.Active = property.Active;//default to true, meaning property is avaliable for association p.Balance = 0; p.Block = block; p.Notes = property.Notes; p.NumberOfResidents = property.NumberOfResidents; p.PropertyNumber = property.PropertyNumber; p.Sold = property.Sold; p.PhoneNumber = property.PhoneNumber; uow.PropertyRepository.Insert(p); uow.Save(); TempData["result"] = "单元创建成功!"; return RedirectToAction("Details", "Block", new { id = property.BlockId }); } else { ModelState.AddModelError("", "该电话号码已被注册,请重新输入"); } } return View(property); }
// GET: /Property/Create public ActionResult Create(int? BlockId) { PropertyInsertView property = new PropertyInsertView(); property.Active = true; if (BlockId == null) { property.CanProceed = false; return View(property); } Block block = uow.BlockRepository.Get(b => b.BlockId == BlockId, null, "District").FirstOrDefault(); if (block == null) { property.CanProceed = false; return View(property); } District district = block.District; if (district == null) { property.CanProceed = false; return View(property); } property.CanProceed = true; property.BlockId = block.BlockId; property.DistrictId = district.DistrictId; property.districtName = district.Name; property.blockName = block.BlockName; return View(property); }