private void IsExistsName(ISession session, Unit unit) { ICriteria criteria = session.CreateCriteria(typeof(Unit)); ICriterion criterion = null; if (unit.Id != Guid.Empty) { criterion = Restrictions.Not(Restrictions.IdEq(unit.Id)); criteria.Add(criterion); } criterion = Restrictions.Eq("UnitName", unit.UnitName); criteria.Add(criterion); //统计 criteria.SetProjection( Projections.ProjectionList() .Add(Projections.Count("Id")) ); int count = (int)criteria.UniqueResult(); if (count > 0) { throw new EasyJob.Tools.Exceptions.UnitNameIsExistsException();//单位名已经存在 } }
public ActionResult Update(Unit unit) { return Json(unitOper.Update(unit, delegate(object sender, ISession session) { //判断是否存在部门Code IsExistsName(session, unit); } )); }
public ActionResult Del(Unit unit) { return Json(unitOper.Del(unit)); }