public ResultModel PledgeUpdateHandle(UserModel user, Model.Pledge pledge, List<Model.PledgeDetial> details) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = pledgeDAL.Get(user, pledge.PledgeId); if (result.ResultStatus != 0) return result; Model.Pledge pledgeRes = result.ReturnValue as Model.Pledge; if (pledgeRes == null) { result.ResultStatus = -1; result.Message = "获取失败"; return result; } pledgeRes.Pledger = user.EmpId; pledgeRes.PledgeTime = DateTime.Now; pledgeRes.PledgeBank = pledge.PledgeBank; pledgeRes.Memo = pledge.Memo; result = pledgeDAL.Update(user, pledgeRes); if (result.ResultStatus != 0) return result; DAL.PledgeDetialDAL pledgeDetialDAL = new PledgeDetialDAL(); result = pledgeDetialDAL.InvalidAll(user, pledge.PledgeId); if (result.ResultStatus != 0) return result; foreach (Model.PledgeDetial detail in details) { detail.PledgeId = pledge.PledgeId; result = pledgeDetialDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (log.IsInfoEnabled) log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
public ResultModel PledgeCreateHandle(UserModel user, Model.Pledge pledge, List<Model.PledgeDetial> details) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = pledgeDAL.Insert(user, pledge); if (result.ResultStatus != 0) return result; int pledgeId = (int)result.ReturnValue; DAL.PledgeDetialDAL pledgeDetialDAL = new PledgeDetialDAL(); foreach (Model.PledgeDetial detail in details) { detail.PledgeId = pledgeId; result = pledgeDetialDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = pledgeId; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (log.IsInfoEnabled) log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }