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); } } } }
private void bwUpdateOutsoleMaterial_DoWork(object sender, DoWorkEventArgs e) { outsoleMaterialRejectUpdateList = new List <OutsoleMaterialModel>(); var outsoleMaterialDetailAferInsertList = OutsoleMaterialDetailController.Select(productNo).Where(w => w.OutsoleSupplierId == supplierClicked.OutsoleSupplierId).ToList(); var sizeNoList = outsoleMaterialDetailAferInsertList.Select(s => s.SizeNo).Distinct().ToList(); foreach (var sizeNo in sizeNoList) { var firstModel = outsoleMaterialDetailAferInsertList.FirstOrDefault(); var outsoleMaterialUpdateReject = new OutsoleMaterialModel() { ProductNo = firstModel.ProductNo, OutsoleSupplierId = firstModel.OutsoleSupplierId, SizeNo = sizeNo, QuantityReject = outsoleMaterialDetailAferInsertList.Where(w => w.SizeNo == sizeNo).Sum(s => s.Reject), }; outsoleMaterialRejectUpdateList.Add(outsoleMaterialUpdateReject); } foreach (var updateModel in outsoleMaterialRejectUpdateList) { OutsoleMaterialController.UpdateRejectFromOutsoleMaterialDetail(updateModel); } // Update Outsole RawMaterial. If Reject > 0 => Remove Actual Date var POAndSupplierHasRejectList = outsoleMaterialRejectUpdateList.Where(w => w.QuantityReject > 0).Select(s => new { ProductNo = s.ProductNo, OutsoleSupplierId = s.OutsoleSupplierId }).Distinct().ToList(); foreach (var p in POAndSupplierHasRejectList) { var updateModel = new OutsoleRawMaterialModel() { ProductNo = p.ProductNo, OutsoleSupplierId = p.OutsoleSupplierId, ActualDate = dtDefault }; OutsoleRawMaterialController.UpdateActualDate(updateModel); } }