public async Task <bool> Delete(int glueid, int ingredientid) { var glueIngredient = _repoGlueIngredient.FindSingle(x => x.GlueID == glueid && x.IngredientID == ingredientid); if (glueIngredient != null) { _repoGlueIngredient.Remove(glueIngredient); return(await _repoGlueIngredient.SaveAll()); } else { return(false); } }
public async Task CloneGlueByCloneDto(CloneDto clone, BPFCEstablish bpfc, BPFCEstablish bpfcClone) { var gluesData = new List <Glue>(); if (bpfcClone.Glues == null) { gluesData = bpfc.Glues.Where(x => x.isShow == true).ToList(); } else { var list2 = bpfcClone.Glues.Where(x => x.isShow == true).Select(x => x.Name); var list1 = bpfc.Glues.Where(x => x.isShow == true).Select(x => x.Name); var check = list1.Except(list2); gluesData = bpfc.Glues.Where(x => x.isShow == true && check.Contains(x.Name)).ToList(); } if (gluesData.Count == 0) { return; } foreach (var item in gluesData) { var glue = new Glue(); glue.Code = await this.GenatateGlueCode(item.Code); glue.Name = item.Name; glue.isShow = true; 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 = bpfcClone.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(); } }
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 }); } }