private void bwInsert_DoWork(object sender, DoWorkEventArgs e) { // Delete RackPosition foreach (var rackModelDetele in outsoleMaterialRackPositionToDeleteList) { OutsoleMaterialRackPositionController.Delete(rackModelDetele); } // Update RackPosition foreach (var rackModelInsert in outsoleMaterialRackPositionToInsertList) { OutsoleMaterialRackPositionController.Insert(rackModelInsert); } foreach (OutsoleRawMaterialModel model in outsoleRawMaterialToInsertList) { OutsoleRawMaterialController.UpdateActualDate(model); } foreach (OutsoleMaterialModel model in outsoleMaterialToInsertList) { var osMaterialDB = OutsoleMaterialController.Select(model.ProductNo).Where(w => w.SizeNo == model.SizeNo && w.OutsoleSupplierId == model.OutsoleSupplierId).FirstOrDefault(); // Insert if (osMaterialDB == null) { OutsoleMaterialController.Insert(model); } // Update else { // Update Quantity if (osMaterialDB.Quantity != model.Quantity) { OutsoleMaterialController.Update(model, false, true, false); } // Update Reject if (osMaterialDB.QuantityReject != model.QuantityReject) { OutsoleMaterialController.Update(model, true, false, false); } // Update Reject Assembly if (osMaterialDB.RejectAssembly != model.RejectAssembly) { OutsoleMaterialController.Update(model, true, false, true); } } } }