private void IsExistsBarCode(ISession session, GoodsInfo goods) { ICriteria criteria = session.CreateCriteria(typeof(GoodsInfo)); ICriterion criterion = null; if (goods.Id != Guid.Empty) { criterion = Restrictions.Not(Restrictions.IdEq(goods.Id)); criteria.Add(criterion); } criterion = Restrictions.Eq("BarCode", goods.BarCode); criteria.Add(criterion); //统计 criteria.SetProjection( Projections.ProjectionList() .Add(Projections.Count("Id")) ); int count = (int)criteria.UniqueResult(); if (count > 0) { throw new EasyJob.Tools.Exceptions.GoodsInfoBarCodeIsExistsException();//商品资料Code已经存在 } }
public ActionResult Add(GoodsInfo goodsInfo) { return Json(goodsInfoOper.Add(goodsInfo, delegate(object sender, ISession session) { //判断是否存在商品资料Code IsExistsCode(session, goodsInfo); //判断是否存在商品资料BarCode IsExistsBarCode(session, goodsInfo); } )); }
public ActionResult Del(GoodsInfo goodsInfo) { return Json(goodsInfoOper.Del(goodsInfo)); }