/// <summary> /// 获取单元户Id, 如果没有将新建一个单元户 /// </summary> /// <param name="doorName"></param> /// <param name="unitId"></param> /// <returns></returns> private static int GetBuildDoorId(string doorName, int unitId) { int doorId = 0; //楼座接口 IBuildDoorBLL doorBll = BLLFactory <IBuildDoorBLL> .GetBLL("BuildDoorBLL"); var door = doorBll.GetEntity(b => b.DoorName == doorName && b.UnitId == unitId); if (door != null) { doorId = door.Id; } else { door = new T_BuildDoor() { DoorName = doorName, UnitId = unitId }; try { doorBll.Save(door); doorId = door.Id; } catch (Exception) { doorId = 0; } } return(doorId); }
public ActionResult AddDoor(BuildDoorSearchModel model) { JsonModel jm = new JsonModel(); IBuildDoorBLL doorBll = BLLFactory <IBuildDoorBLL> .GetBLL("BuildDoorBLL"); if (doorBll.Exist(m => m.DoorName == model.DoorName && m.Id != model.DoorId && m.UnitId == model.UnitId)) { jm.Msg = "该单元户名称已经存在"; } //如果表单模型验证成功 else if (ModelState.IsValid) { T_BuildDoor newDoor = new T_BuildDoor() { DoorName = model.DoorName, UnitId = model.UnitId }; // 保存到数据库 doorBll.Save(newDoor); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }