public async Task <List <BPFCRecordDto> > GetAllBPFCRecord(Status status, string startBuildingDate, string endBuildingDate) { var lists = _repoBPFCEstablish.FindAll().ProjectTo <BPFCRecordDto>(_configMapper).OrderByDescending(x => x.ID); var result = new List <BPFCRecordDto>(); if (status == Status.All && !startBuildingDate.IsNullOrEmpty() && !endBuildingDate.IsNullOrEmpty()) { var start = Convert.ToDateTime(startBuildingDate).Date; var end = Convert.ToDateTime(endBuildingDate).Date; result = await lists.Where(x => x.BuildingDate.Value.Date >= start && x.BuildingDate.Value.Date <= end).ToListAsync(); } if (status == Status.Done && !startBuildingDate.IsNullOrEmpty() && !endBuildingDate.IsNullOrEmpty()) { var start = Convert.ToDateTime(startBuildingDate).Date; var end = Convert.ToDateTime(endBuildingDate).Date; result = await lists.Where(x => x.BuildingDate.Value.Date >= start && x.BuildingDate.Value.Date <= end && x.FinishedStatus == true).ToListAsync(); } if (status == Status.Done) { result = await lists.Where(x => x.FinishedStatus == true).ToListAsync(); } if (status == Status.All) { result = await lists.ToListAsync(); } if (!startBuildingDate.IsNullOrEmpty() && !endBuildingDate.IsNullOrEmpty()) { var start = Convert.ToDateTime(startBuildingDate).Date; var end = Convert.ToDateTime(endBuildingDate).Date; result = await lists.Where(x => x.BuildingDate.Value.Date >= start && x.BuildingDate.Value.Date <= end).ToListAsync(); } if (result.Count > 0) { result.ForEach(item => { var glue = _repoGlue.FindAll().FirstOrDefault(x => x.isShow == true && x.BPFCEstablishID == item.ID); if (glue != null) { var ingredient = _repoGlueIngredient.FindAll().Include(x => x.Ingredient).ThenInclude(x => x.Supplier).FirstOrDefault(x => x.GlueID == glue.ID && x.Position == "A"); if (ingredient != null) { item.Supplier = ingredient.Ingredient.Supplier.Name ?? "#N/A"; } else { item.Supplier = "#N/A"; } } else { item.Supplier = "#N/A"; } }); } return(result); }
public async Task <bool> MapGlueIngredient(GlueIngredient glueIngredient) { if (glueIngredient.Position.IsNullOrEmpty()) { return(false); } var item = await _repoGlueIngredient.FindAll().FirstOrDefaultAsync(x => x.GlueID == glueIngredient.GlueID && x.IngredientID == glueIngredient.IngredientID); if (item == null) { _repoGlueIngredient.Add(glueIngredient); return(await _repoGlueIngredient.SaveAll()); } else { item.Percentage = glueIngredient.Percentage; item.Allow = glueIngredient.Allow; item.Position = glueIngredient.Position; return(await _repoGlueIngredient.SaveAll()); } }
//Cập nhật Brand public async Task <bool> UpdateChemical(GlueCreateDto model) { var glue = _mapper.Map <Glue>(model); _repoGlue.Update(glue); var item = _repoGlueIngredient.FindAll().FirstOrDefault(x => x.GlueID.Equals(model.ID) && x.Percentage == 100); if (item != null) { item.IngredientID = model.IngredientID; return(await _repoGlue.SaveAll()); } else { return(false); } }
public object GetGlueIngredientDetail(int glueid) { var glueIngredient = (from a in _repoGlueIngredient.FindAll() join b in _repoGlue.FindAll() on a.GlueID equals b.ID join c in _repoIngredient.FindAll() on a.IngredientID equals c.ID where a.GlueID == glueid select new GlueIngredientDetailDto { ID = a.ID, GlueID = a.GlueID, IngredientID = a.IngredientID, GlueName = b.Name, IngredientName = c.Name, CreatedDate = a.CreatedDate, Percentage = a.Percentage }); var parent = new GlueIngredientForGroupByDto(); var childs = new List <GlueIngredientDetailDto>(); foreach (var item in glueIngredient) { parent.ID = item.ID; parent.Name = item.GlueName; childs.Add(new GlueIngredientDetailDto { IngredientID = item.IngredientID, IngredientName = item.IngredientName, GlueID = item.GlueID, CreatedDate = item.CreatedDate, GlueName = item.GlueName, Percentage = item.Percentage }); } parent.GlueIngredients = childs; return(parent); }