Exemple #1
0
        private async Task <bool> CheckUpdateData(BPFCEstablishDtoForImportExcel bPFCEstablishDto)
        {
            var model = await(from m in _repoModelName.FindAll()
                              join n in _repoModelNo.FindAll() on m.ID equals n.ModelNameID
                              join a in _repoArticleNo.FindAll() on n.ID equals a.ModelNoID
                              join ap in _repoArtProcess.FindAll().Include(x => x.Process) on a.ID equals ap.ArticleNoID
                              select new BPFCEstablishDtoForImportExcel
            {
                ModelName   = m.Name,
                ModelNo     = n.Name,
                ArticleNo   = a.Name,
                Process     = ap.Process.Name,
                CreatedBy   = bPFCEstablishDto.CreatedBy,
                CreatedDate = bPFCEstablishDto.CreatedDate
            }).ToListAsync();

            return(model.Any(x => x.ModelName == bPFCEstablishDto.ModelName &&
                             x.ModelNo == bPFCEstablishDto.ModelNo &&
                             x.ArticleNo == bPFCEstablishDto.ArticleNo &&
                             x.Process == bPFCEstablishDto.Process));
        }
Exemple #2
0
        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);
            }
        }