/// <summary> /// 客户的地址 /// </summary> /// <returns></returns> public ActionResult Get(Customer cstmr) { IList<CustomerAddr> retVal = null; ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); //查找客户ID string openId = cstmr.OpenId; cstmr = PojoUtil.GetCust(s, openId); if (cstmr == null) { //客户不存在 throw new Exceptions.CstmrIsNotExistsException(); } else { //查找客户的所有地址 ICriteria criteria = s.CreateCriteria(typeof(CustomerAddr)); criteria.Add(Restrictions.Eq("Cstmr", cstmr)); retVal = criteria.List<CustomerAddr>(); } trans.Commit(); } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } return Json(retVal); }
public ActionResult Del(Customer customer) { return Json(customerOper.Del(customer)); }
public ActionResult Update(Customer customer) { return Json(customerOper.Update(customer)); }
public ActionResult Add(Customer customer) { return Json(customerOper.Add(customer)); }
//查找地址码 public ActionResult Add(WorkAndWorkTypeDetails wawtd) { bool retVal = false; Work work = wawtd.Work;//主工单 WorkSub workSub = wawtd.WorkSub;//子工单 if (workSub == null) { workSub = new WorkSub(); } IList<WorkTypeDetail> workTypeDetails = wawtd.WorkTypeDetails;//子工单维修类型 IList<WorkPic> workPics=wawtd.WorkPics;//子工单图片 ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); //如果主工单的ID不存在则新建主工单,有可能是在原来的主工单基础上追加的子工单就会把主工单的ID传过来 if (work.Id == Guid.Empty) { //生成工单编号 work.Code = DateTime.Now.ToString("yyyyMMddHHmmssfffff"); //查找客户ID string openId = work.Cstmr.OpenId; work.Cstmr = PojoUtil.GetCust(s, openId); if (work.Cstmr == null) { Customer cstmr = new Customer(); cstmr.OpenId = openId; s.Save(cstmr); work.Cstmr = cstmr; } //保存工单 s.Save(work); } else { //根据工单ID找到工单 work = s.Get<Work>(work.Id); if (work == null) { //工单不存在 throw new Exceptions.WorkIsNotFoundException(); } } //保存子工单 //如果子工单的下单员工存在 if (workSub.OrderEmp != null) { //如果子工单的下单员ID存在 if(workSub.OrderEmp.Id != Guid.Empty){ workSub.OrderEmp = s.Get<Employee>(workSub.OrderEmp.Id); } //如果子工单的下单员工号存在 if (workSub.OrderEmp.Code != null && !workSub.OrderEmp.Code.ToString().Equals("")) { workSub.OrderEmp = PojoUtil.GetEmployee(s, workSub.OrderEmp.Code); } if (workSub.OrderEmp == null) { //该下单员不存在 throw new Exceptions.EmployeeIsNotFoundException(); } } workSub.Work = work; //根据工单地址自动分配任务到分店 workSub.Dept = PojoUtil.GetMinDistDept(s, work); s.Save(workSub); //保存维修类型 if (workTypeDetails != null) { foreach (WorkTypeDetail wtd in workTypeDetails) { wtd.WorkSub = workSub; s.Save(wtd); } } else { //维修类型明细不存在 throw new Exceptions.WorkTypeDetailIsNotFoundException(); } //保存图片 if (workPics != null) { foreach (WorkPic wp in workPics) { wp.WorkSub = workSub; s.Save(wp); } } trans.Commit(); retVal = true; } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } return Json(retVal); }
/// <summary> /// 添加客户的地址 /// </summary> /// <param name="cstmrAddr"></param> /// <returns></returns> public ActionResult Add(CustomerAddr cstmrAddr) { CustomerAddr retVal = null; ISession s = null; ITransaction trans = null; try { s = HibernateOper.GetCurrentSession(); trans = s.BeginTransaction(); //查找客户ID if (cstmrAddr.AddrCode != null && !cstmrAddr.AddrCode.Equals("")) { cstmrAddr.Addr = PojoUtil.GetAddrForCode(s, cstmrAddr.AddrCode); LocationUtil.Location loc = LocationUtil.GetLocation(cstmrAddr.Addr+cstmrAddr.Location); if (loc != null) { cstmrAddr.Lat = loc.lat; cstmrAddr.Lng = loc.lng; } } string openId = cstmrAddr.Cstmr.OpenId; cstmrAddr.Cstmr = PojoUtil.GetCust(s, openId); if (cstmrAddr.Cstmr == null) { if (openId == null || openId.Equals("")) { //客户不存在 throw new Exceptions.CstmrIsNotExistsException(); } Customer cstmr = new Customer(); cstmr.OpenId = openId; s.Save(cstmr); cstmrAddr.Cstmr = cstmr; } s.Save(cstmrAddr); trans.Commit(); retVal = cstmrAddr; } catch (Exception e) { if (trans != null) { trans.Rollback(); } throw e; } return Json(retVal); }