private void ProcessOrderHistoryDetailOnDeletedOrPurgedStatusUpdate(EF.OrderHistoryDetail detail) { EF.OrderHistoryHeader header = detail.OrderHistoryHeader; if (header != null) { if (header.OrderDetails.Count > 1) { _detailRepo.Delete(detail); } else { _headerRepo.Delete(header); } _unitOfWork.SaveChanges(); } else { _detailRepo.Delete(detail); _unitOfWork.SaveChanges(); } }
private void RemoveSpecialOrderItemsFromHistory(EF.OrderHistoryHeader order) { // clean up any previous orders where the special order item existed var specialOrderInfo = order.OrderDetails.Where(currentDetail => !String.IsNullOrEmpty(currentDetail.SpecialOrderHeaderId)) .Select(d => new { HeaderId = d.SpecialOrderHeaderId, LineNumber = d.SpecialOrderLineNumber }) .Distinct() .ToList(); // loop through each special order item in the current order foreach (var specialOrderItem in specialOrderInfo) { // find all detail records with the current line's special order info that is not the current order var specialLines = _detailRepo.Read(d => d.BranchId.Equals(order.BranchId) && d.SpecialOrderHeaderId.Equals(specialOrderItem.HeaderId) && d.SpecialOrderLineNumber.Equals(specialOrderItem.LineNumber) && !d.InvoiceNumber.Equals(order.InvoiceNumber)) .ToList(); // loop through each found detail record foreach (var line in specialLines) { _detailRepo.Delete(line); // check to see if there are any more records on the detail's header record if (_detailRepo.Read(d => d.BranchId.Equals(line.BranchId) && d.InvoiceNumber.Equals(line.InvoiceNumber)) .Any() == false) { _headerRepo.Delete(h => h.BranchId.Equals(line.BranchId) && h.InvoiceNumber.Equals(line.InvoiceNumber)); } } } // this is commented out so that all updates to EF happen in one transaction for the current order //_unitOfWork.SaveChanges(); }