/// <summary> /// 添加消息(此方法无事务) /// </summary> /// <param name="user"></param> /// <param name="sms"></param> /// <param name="smsDetails"></param> /// <returns></returns> public ResultModel AddSms(UserModel user, Model.Sms sms, List<Model.SmsDetail> smsDetails) { ResultModel result = new ResultModel(); DAL.SmsDetailDAL smsDetailDAL = new SmsDetailDAL(); try { result = this.Insert(user, sms); if (result.ResultStatus != 0) return result; int smsId = (int)result.ReturnValue; if (smsDetails != null && smsDetails.Count > 0) { foreach (Model.SmsDetail detail in smsDetails) { detail.SmsId = smsId; result = smsDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } } if (result.ResultStatus == 0) result.Message = "消息添加成功"; } catch (Exception e) { result.ResultStatus = -1; result.Message = e.Message; } return result; }
/// <summary> /// 添加消息(此方法有事务) /// </summary> /// <param name="user">用户</param> /// <param name="sms">消息内容</param> /// <param name="smsDetails">消息明细</param> /// <returns></returns> public ResultModel AddSms(UserModel user, Model.Sms sms, List<Model.SmsDetail> smsDetails) { ResultModel result = new ResultModel(); DAL.SmsDetailDAL smsDetailDAL = new SmsDetailDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = smsDAL.Insert(user, sms); if (result.ResultStatus != 0) return result; int smsId = (int)result.ReturnValue; foreach (Model.SmsDetail detail in smsDetails) { detail.SmsId = smsId; result = smsDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.Message = "消息添加成功"; scope.Complete(); } } catch (Exception e) { result.ResultStatus = -1; result.Message = e.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }