private void IsExistsCode(ISession session, VendorInfo vi) { ICriteria criteria = session.CreateCriteria(typeof(VendorInfo)); ICriterion criterion = null; if (vi.Id != Guid.Empty) { criterion = Restrictions.Not(Restrictions.IdEq(vi.Id)); criteria.Add(criterion); } criterion = Restrictions.Eq("VendorCode", vi.VendorCode); criteria.Add(criterion); //统计 criteria.SetProjection( Projections.ProjectionList() .Add(Projections.Count("Id")) ); int count = (int)criteria.UniqueResult(); if (count > 0) { throw new EasyJob.Tools.Exceptions.VendorInfoCodeIsExistsException();//供应商Code已经存在 } }
public ActionResult Add(VendorInfo vendorInfo) { //根据地址码获取地址 vendorInfo.Addr = PojoUtil.GetAddrForCode(HibernateOper, vendorInfo.AddrCode); LocationUtil.Location loc = LocationUtil.GetLocation(vendorInfo.Addr + vendorInfo.Location); if (loc != null) { vendorInfo.Lat = loc.lat; vendorInfo.Lng = loc.lng; } return Json(vendorInfoOper.Add(vendorInfo, delegate(object sender, ISession session) { //判断是否存在部门Code IsExistsCode(session, vendorInfo); } )); }
public ActionResult Del(VendorInfo vendorInfo) { return Json(vendorInfoOper.Del(vendorInfo)); }