Exemplo n.º 1
0
 public override int Update(MaterialTypeBO vo)
 {
     if (Repository.Count(x => x.Code == vo.Code) > 0)
     {
         throw new BusinessException(ResponseCode.CodeAlreadyExists.Format(vo.Code));
     }
     if (vo.Configs != null && vo.Configs.Count > 0)
     {
         MaterialTypeConfigRepository.Delete(x => x.MaterialTypeId == vo.Id);
         MaterialTypeConfigRepository.BulkInsert(Mapper.Map <List <MaterialTypeConfig> >(vo.Configs));
         if (vo.OverrideMaterialConfigs.HasValue && vo.OverrideMaterialConfigs.Value)  //覆盖物料的参数配置
         {
             var materialIds = MaterialRepository.Find(x => x.TypeId == vo.Id).Select(x => x.Id);
             foreach (var config in vo.Configs)
             {
                 var configs = MaterialConfigRepository.Find(x => materialIds.Contains(x.MaterialId));
                 foreach (var item in configs)
                 {
                     item.ConfigValue = config.ConfigDefaultValue;
                 }
                 MaterialConfigRepository.BulkUpdate(configs);
             }
         }
     }
     return(base.Update(vo));
 }
Exemplo n.º 2
0
        public override int?Add(MaterialTypeBO bo)
        {
            var count = Repository.Count(x => x.Code.Equals(bo.Code));

            if (count > 0)
            {
                throw new BusinessException(ResponseCode.CodeAlreadyExists.Format(bo.Code));
            }
            var id = base.Add(bo);

            if (bo.Configs != null && bo.Configs.Count > 0)
            {
                bo.Configs.AsParallel().ForAll(x =>
                {
                    x.MaterialTypeId = id;
                    x.Id             = null;
                });
                MaterialTypeConfigRepository.BulkInsert(Mapper.Map <List <MaterialTypeConfig> >(bo.Configs));
            }
            return(id);
        }