public void AddMailHoldLogs(string[] trackNumbers) { trackNumbers.ToList().ForEach(p => { var wayBill = _wayBillInfoRepository.GetFiltered(w => w.TrackingNumber == p).First(); if (wayBill.Status != (int)WayBill.StatusEnum.Send && wayBill.Status == (int)WayBill.StatusEnum.WaitOrder) { throw new Exception(string.Format("单:{0}不为已发货或待转单状态", p)); } _mailHoldLogRepository.Add(new MailHoldLog() { TrackingNumber = p, CreatedBy = _workContext.User.UserUame, HoldBy = _workContext.User.UserUame, LastUpdatedBy = _workContext.User.UserUame, HoldOn = DateTime.Now, CreatedOn = DateTime.Now, LastUpdatedOn = DateTime.Now, }); _wayBillEventLogRepository.Add(new WayBillEventLog() { WayBillNumber = wayBill.WayBillNumber, EventCode = 636, EventDate = DateTime.Now, Description = "拦截", Operator = _workContext.User.UserUame, LastUpdatedOn = DateTime.Now, Remarks = string.Format("包裹异常处理中") }); }); using ( var transaction = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 5, 0))) { _mailHoldLogRepository.UnitOfWork.Commit(); _wayBillEventLogRepository.UnitOfWork.Commit(); transaction.Complete(); } }