public Result GenerateImeiBatch(long userId, long projectId, string imeiCode) { IProduction iProductionSelect = new WCMS_DAL_Production(); var result = new Result(); try { var productionMasterInfo = _isSelectingCommon.ProductionMasterInfoByImei(imeiCode).FirstOrDefault(); if (productionMasterInfo != null && productionMasterInfo.Passed == "Y") { var isExists = iProductionSelect.GetPackagingBatchInfo(new tblPackagingBatch() { MobileCode = productionMasterInfo.MobileCode }).Any(); if (!isExists) { var packaginBatch = new tblPackagingBatch(); packaginBatch.ProjectId = productionMasterInfo.ProjectId; packaginBatch.LineId = productionMasterInfo.LineId; packaginBatch.MobileCode = productionMasterInfo.MobileCode; packaginBatch.Imei1 = productionMasterInfo.Imei1; packaginBatch.Imei2 = productionMasterInfo.Imei2; packaginBatch.AddedBy = userId; packaginBatch.AddedDate = DateTime.Now; result.IsSuccess = iProductionSelect.GenerateImeiBatch(packaginBatch); if (result.IsSuccess) { var packagingBatchList = iProductionSelect.CountPackagingBatch(projectId, userId).ToList(); if (packagingBatchList.Count == 100) { var pckResult = new Result(); var packageBatchList = new List <tblPackagingBatch>(); var productionList = new List <ProductionMaster>(); var packagingBatchNumber = PackagingRandomString(); foreach (var items in packagingBatchList) { var packagingBatch = new tblPackagingBatch(); var productionMaster = new ProductionMaster(); packagingBatch.MobileCode = items.MobileCode; packagingBatch.Imei1 = items.Imei1; packagingBatch.Imei2 = items.Imei2; packagingBatch.SystemBatch = "PKG-" + packagingBatchNumber.Trim(); packagingBatch.BatchCreatedBy = userId; packagingBatch.BatchCreatedDate = DateTime.Now; packageBatchList.Add(packagingBatch); //packBatchList //adding productonMaster productionMaster.MobileCode = items.MobileCode; productionMaster.Imei1 = items.Imei1; productionMaster.Imei2 = items.Imei2; productionMaster.OQCBatchNumber = "PKG-" + packagingBatchNumber.Trim(); productionList.Add(productionMaster); } pckResult.IsSuccess = iProductionSelect.UpdatePackagingBatchStatus(packageBatchList); if (pckResult.IsSuccess) { var rslt = new Result { IsSuccess = _iProductionInsert.UpdateQcStatusHistory(productionList) }; } } } } else { result.Message = "Already Exists ! duplicate IMEI "; return(result); } } else { result.Message = "No data found with this IMEI / Not Passed "; return(result); } } catch (Exception ex) { throw ex; } return(result); }