Exemplo n.º 1
0
        private IList <DishBom> GetDishBoms(string boms, SixMan.ChiMa.Domain.Dish.Dish dish)
        {
            List <DishBom> result = new List <DishBom>();

            foreach (var bom in boms.Split(';'))
            {
                var    vs           = bom.Split(':');
                long   foodImportId = long.Parse(vs[0]);
                double match        = double.Parse(vs[1]);
                var    fdmId        = _foodMaterialRepository.GetAll().AsNoTracking()
                                      .Where(fm => fm.ImportId == foodImportId)
                                      .FirstOrDefault()?.Id;
                if (fdmId == null)
                {
                    throw new Exception($"{foodImportId} 找不到");
                }
                var dm = new DishBom()
                {
                    FoodMaterialId = fdmId.Value,
                    Matching       = match
                };

                result.Add(dm);
            }

            return(result);
        }
Exemplo n.º 2
0
        protected override void AttachChild(DishDto dto, SixMan.ChiMa.Domain.Dish.Dish entity)
        {
            var dishBoms = dto.DishBoms;

            entity.DishBoms = new List <DishBom>(); //取消关联

            foreach (var item in dishBoms)
            {
                DishBom dbEntity = null;
                if (item.Id == 0)
                {
                    if (!item.ClientDelete)
                    {
                        dbEntity = ObjectMapper.Map <DishBom>(item);
                        //_dishBomRepository.Insert(dbEntity);
                    }
                }
                else
                {
                    if (!item.ClientDelete)
                    {
                        dbEntity = _dishBomRepository.Get(item.Id);
                        ObjectMapper.Map(item, dbEntity);
                        //_dishBomRepository.Update(dbEntity);
                    }
                    else
                    {
                        _dishBomRepository.Delete(item.Id);
                    }
                }
                if (dbEntity != null)
                {
                    entity.DishBoms.Add(dbEntity);
                }
            }
        }