//Thêm Brand mới vào bảng ModelName public async Task <bool> Add(ModelNameDto model) { var ModelName = _mapper.Map <ModelName>(model); _repoModelName.Add(ModelName); return(await _repoModelName.SaveAll()); }
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); } }