public void InsertBillStateHistory(IBill bill, BillStates state, string remarks, DateTime? date = null) { ExceptionHelper.ThrowIfNull(bill, "bill"); var entity = new Data.BillStateHistory { bid = bill.Bid, created = DateTime.Now, state_updated = date ?? DateTime.Now, creater = _User.Uid, remarks = remarks.SafeTrim().GetSafeDbString(), state = state, enabled = true, }; _BillStateHistoryRepository.Add(entity); _BillStateHistoryRepository.SaveChanges(); }
public void UpdateBillState(IBill bill, BillStates state, string remarks, DateTime? date = null) { ExceptionHelper.ThrowIfNull(bill, "bill"); if (state == bill.State) { UpdateLastStateHistoryRemarksIfMatchState(bill, state, remarks); return; } using (var scope = new System.Transactions.TransactionScope()) { bill.UpdateState(_User, state); _BillRepository.SaveChanges(); InsertBillStateHistory(bill, state, remarks, date); scope.Complete(); } }
private void UpdateLastStateHistoryRemarksIfMatchState(IBill bill, BillStates currentState, string remarks) { if (String.IsNullOrWhiteSpace(remarks)) return; var entity = _BillStateHistoryRepository.Entities .Where(h => h.enabled && h.bid == bill.Bid) .OrderByDescending(h => h.state_updated) .FirstOrDefault(); if (entity.state == currentState) { entity.remarks = remarks.Trim(); _BillStateHistoryRepository.SaveChanges(); } }
public void UpdateState(long uid, long[] bids, BillStates state, string remarks, DateTime? date) { ExceptionHelper.ThrowIfNullOrEmptyIds(ref bids, "bids"); var user = _UserManager.GetUser(uid); IBillManagerUser manager = new BillUser(user, _BillRepository, _BillStateHistoryRepository); using (var scope = new System.Transactions.TransactionScope()) { foreach (var bid in bids) { var bill = _BillManager.GetBill(bid); var authority = new BillAuthority(user, bill); if (!authority.AllowUpdateState) throw new BHException(ErrorCode.NotAllow, "没有权限更新运单状态,单号:" + bill.No); manager.UpdateBillState(bill, state, remarks, date); } scope.Complete(); } }