Example #1
0
        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);
            }
        }