public async Task <bool> Add(ArtProcessDto model) { var artProcess = _mapper.Map <ArtProcess>(model); _repoArticalNo.Add(artProcess); return(await _repoArticalNo.SaveAll()); }
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); } }
private async Task <BPFCEstablishDto> AddBPFC(BPFCEstablishDtoForImportExcel bPFCEstablishDto) { var result = new BPFCEstablishDto(); // make model name, model no, article no, process using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }, TransactionScopeAsyncFlowOption.Enabled)) { // make model name var modelName = await _repoModelName.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(bPFCEstablishDto.ModelName.ToUpper())); if (modelName != null) { result.ModelNameID = modelName.ID; } else { var modelNameModel = new ModelName { Name = bPFCEstablishDto.ModelName }; _repoModelName.Add(modelNameModel); await _repoModelNo.SaveAll(); result.ModelNameID = modelNameModel.ID; } // end make model no // Make model no var modelNo = await _repoModelNo.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(bPFCEstablishDto.ModelNo.ToUpper()) && x.ModelNameID == result.ModelNameID); if (modelNo != null) { result.ModelNoID = modelNo.ID; } else { var modelNoModel = new ModelNo { Name = bPFCEstablishDto.ModelNo, ModelNameID = result.ModelNameID }; _repoModelNo.Add(modelNoModel); await _repoModelNo.SaveAll(); result.ModelNoID = modelNoModel.ID; } // end make model NO // end make articleNO var artNo = await _repoArticleNo.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(bPFCEstablishDto.ArticleNo.ToUpper()) && x.ModelNoID == result.ModelNoID); if (artNo != null) { result.ArticleNoID = artNo.ID; } else { // make art no var articleNoModel = new ArticleNo { Name = bPFCEstablishDto.ArticleNo, ModelNoID = result.ModelNoID }; _repoArticleNo.Add(articleNoModel); await _repoArticleNo.SaveAll(); result.ArticleNoID = articleNoModel.ID; } // end articleNO // make Art Process var artProcess = await _repoArtProcess.FindAll().FirstOrDefaultAsync(x => x.ProcessID.Equals(bPFCEstablishDto.Process.ToUpper() == "STF" ? 2 : 1) && x.ArticleNoID == result.ArticleNoID); if (artProcess != null) { result.ArtProcessID = artProcess.ID; } else { // make art process var artProcessModel = new ArtProcess { ArticleNoID = result.ArticleNoID, ProcessID = bPFCEstablishDto.Process.ToUpper() == "STF" ? 2 : 1 }; _repoArtProcess.Add(artProcessModel); await _repoArtProcess.SaveAll(); result.ArtProcessID = artProcessModel.ID; } //End make Art Process result.CreatedBy = bPFCEstablishDto.CreatedBy; scope.Complete(); return(result); } }