public ActionResult AddUnit(BuildUnitSearchModel model) { JsonModel jm = new JsonModel(); IBuildUnitBLL unitBll = BLLFactory <IBuildUnitBLL> .GetBLL("BuildUnitBLL"); if (unitBll.Exist(m => m.UnitName == model.UnitName && m.Id != model.UnitId && m.BuildId == model.BuildId)) { jm.Msg = "该单元名称已经存在"; } //如果表单模型验证成功 else if (ModelState.IsValid) { T_BuildUnit newUnit = new T_BuildUnit() { UnitName = model.UnitName, BuildId = model.BuildId }; // 保存到数据库 unitBll.Save(newUnit); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取单元Id, 如果没有将新建一个单元 /// </summary> /// <param name="unitName"></param> /// <param name="buildId"></param> /// <returns></returns> private static int GetBuildUnitId(string unitName, int buildId) { int unitId = 0; //楼座接口 IBuildUnitBLL unitBll = BLLFactory <IBuildUnitBLL> .GetBLL("BuildUnitBLL"); var unit = unitBll.GetEntity(b => b.UnitName == unitName && b.BuildId == buildId); if (unit != null) { unitId = unit.Id; } else { unit = new T_BuildUnit() { UnitName = unitName, BuildId = buildId }; try { unitBll.Save(unit); unitId = unit.Id; } catch { unitId = 0; } } return(unitId); }