public async Task <bool> CloneModelName(int modelNameID, int modelNOID, int articleNOID, int processID) { try { using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }, TransactionScopeAsyncFlowOption.Enabled)) { var bpfc = await _repoBPFC.FindAll() .Include(x => x.ModelName) .Include(x => x.ModelNo) .Include(x => x.ArtProcess) .Include(x => x.ArticleNo) .Include(x => x.Glues) .Include(x => x.Plans) .FirstOrDefaultAsync(x => x.ModelNameID == modelNameID && x.ModelNoID == modelNOID && x.ArticleNoID == articleNOID && x.ArtProcessID == processID); if (bpfc == null) { return(false); } var modelNameData = bpfc.ModelName; modelNameData.ID = 0; _repoModelName.Add(modelNameData); await _repoModelName.SaveAll(); var modelNoData = bpfc.ModelNo; modelNoData.ID = 0; modelNoData.ModelNameID = modelNameData.ID; _repoModelNO.Add(modelNoData); await _repoModelNO.SaveAll(); var articleNOData = bpfc.ArticleNo; articleNOData.ID = 0; articleNOData.ModelNoID = modelNoData.ID; _repoArticleNo.Add(articleNOData); await _repoArticleNo.SaveAll(); var artProcessData = bpfc.ArtProcess; artProcessData.ID = 0; artProcessData.ArticleNoID = articleNOData.ID; _repoArtProcess.Add(artProcessData); await _repoArtProcess.SaveAll(); var bpfcData = bpfc; bpfcData.ModelName = null; bpfcData.ModelNo = null; bpfcData.ArticleNo = null; bpfcData.ArtProcess = null; bpfcData.Glues = null; bpfcData.Plans = null; bpfcData.ID = 0; bpfcData.ModelNameID = modelNameData.ID; bpfcData.ModelNoID = modelNoData.ID; bpfcData.ArticleNoID = articleNOData.ID; bpfcData.ArtProcessID = artProcessData.ID; _repoBPFC.Add(bpfcData); await _repoBPFC.SaveAll(); var gluesData = bpfc.Glues.ToList(); gluesData.ForEach(item => { item.ID = 0; item.BPFCEstablishID = bpfcData.ID; }); _repoGlue.AddRange(gluesData); await _repoGlue.SaveAll(); var planData = bpfc.Plans.ToList(); planData.ForEach(item => { item.ID = 0; item.BPFCEstablishID = bpfcData.ID; }); _repoPlan.AddRange(planData); await _repoPlan.SaveAll(); scope.Complete(); } return(true); } catch (Exception ex) { Console.WriteLine("Loi clone model name", ex); return(false); } }