Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public async Task <ArtProcess> FindArtProcessByCloneDto(CloneDto clone)
        {
            var artProcess = await _repoArtProcess.FindAll().FirstOrDefaultAsync(x => x.ArticleNoID == clone.ArticleNOID && x.ProcessID == clone.ArtProcessID);

            if (artProcess != null)
            {
                return(artProcess);
            }
            else
            {
                var artProcessData = new ArtProcess();
                artProcessData.ArticleNoID = clone.ArticleNOID;
                artProcessData.ProcessID   = clone.ArtProcessID;
                _repoArtProcess.Add(artProcessData);
                await _repoGlueIngredient.SaveAll();

                return(artProcessData);
            }
        }
Ejemplo n.º 3
0
        public async Task <PagedList <ArtProcessDto> > GetWithPaginations(PaginationParams param)
        {
            var lists = _repoArticalNo.FindAll().ProjectTo <ArtProcessDto>(_configMapper).OrderByDescending(x => x.ID);

            return(await PagedList <ArtProcessDto> .CreateAsync(lists, param.PageNumber, param.PageSize));
        }
Ejemplo n.º 4
0
        public async Task <object> CloneModelName(CloneDto clone)
        {
            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).ThenInclude(x => x.GlueIngredients)
                               .Include(x => x.Plans)
                               .FirstOrDefaultAsync(x => x.ID == clone.BPFCID);

                    var artProcessFirstAdd = _repoArtProcess.FindAll().FirstOrDefaultAsync(x => x.ArticleNoID == bpfc.ArticleNoID && x.ProcessID == clone.ArtProcessID);
                    if (bpfc == null)
                    {
                        return new
                               {
                                   message = "The BPFC is invalid!",
                                   status  = false
                               }
                    }
                    ;

                    if (artProcessFirstAdd.Result != null)
                    {
                        if (clone.ArtProcessID == artProcessFirstAdd.Result.ProcessID)
                        {
                            clone.ArtProcessID = artProcessFirstAdd.Result.ArticleNoID;
                            await CheckExistBPFC(clone);

                            return(new
                            {
                                message = "The BPFC exists!",
                                status = false
                            });
                        }
                    }

                    var artProcessData = new ArtProcess();
                    artProcessData.ArticleNoID = clone.ArticleNOID;
                    artProcessData.ProcessID   = clone.ArtProcessID;
                    _repoArtProcess.Add(artProcessData);
                    await _repoArtProcess.SaveAll();

                    var artProcessLastAdd = _repoArtProcess.FindAll().FirstOrDefaultAsync(x => x.ArticleNoID == bpfc.ArticleNoID && x.ProcessID == clone.ArtProcessID);

                    var bpfcData = new BPFCEstablish();
                    bpfcData.ModelNameID  = clone.ModelNameID;
                    bpfcData.ModelNoID    = clone.ModelNOID;
                    bpfcData.ArticleNoID  = clone.ArticleNOID;
                    bpfcData.ArtProcessID = artProcessLastAdd.Result.ID;

                    bpfcData.ApprovalStatus = false;
                    bpfcData.FinishedStatus = false;
                    bpfcData.CreatedBy      = clone.CloneBy;
                    bpfcData.ApprovalBy     = 0;
                    bpfcData.CreatedBy      = clone.CloneBy;
                    bpfcData.UpdateTime     = DateTime.Now;
                    bpfcData.BuildingDate   = DateTime.Now;
                    bpfcData.CreatedDate    = DateTime.Now;
                    _repoBPFC.Add(bpfcData);
                    await _repoBPFC.SaveAll();

                    var gluesData = bpfc.Glues.ToList();
                    foreach (var item in gluesData)
                    {
                        var glue = new Glue();

                        glue.Code = await this.GenatateGlueCode(item.Code);

                        glue.Name            = item.Name;
                        glue.Consumption     = item.Consumption;
                        glue.CreatedBy       = clone.CloneBy;
                        glue.MaterialID      = item.MaterialID;
                        glue.KindID          = item.KindID;
                        glue.PartID          = item.PartID;
                        glue.ExpiredTime     = item.ExpiredTime;
                        glue.BPFCEstablishID = bpfcData.ID;
                        _repoGlue.Add(glue);
                        await _repoGlue.SaveAll();

                        var glueIngredients    = item.GlueIngredients.ToList();
                        var glueIngredientData = glueIngredients.Select(x => new GlueIngredient
                        {
                            GlueID       = glue.ID,
                            IngredientID = x.IngredientID,
                            Allow        = x.Allow,
                            Percentage   = x.Percentage,
                            CreatedDate  = DateTime.Now.ToString("MMMM dd, yyyy HH:mm:ss tt"),
                            Position     = x.Position,
                        }).ToList();
                        _repoGlueIngredient.AddRange(glueIngredientData);
                        await _repoGlueIngredient.SaveAll();
                    }

                    scope.Complete();
                }
                return(new
                {
                    message = "The BPFC has been cloned!",
                    status = true
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("Loi clone model name", ex);
                return(new
                {
                    message = "",
                    status = false
                });
            }
        }