public override int Update(MaterialBO bo)
        {
            var type     = MaterialTypeRepository.FindById(bo.TypeId);
            var category = MaterialCategoryRepository.FindById(bo.CategoryId);

            if (category.RequireContainer == true)
            {
                var material = Repository.FindById(bo.ContainerMaterialId);
                if (material == null)
                {
                    throw new BusinessException(ResponseCode.CannotFindMaterialById.Format(bo.ContainerMaterialId));
                }
                bo.ContainerPartNumber = material.PartNumber;
            }
            if (category.RequireRack == true)
            {
                var material = Repository.FindById(bo.RackId);
                if (material == null)
                {
                    throw new BusinessException(ResponseCode.CannotFindMaterialById.Format(bo.RackId));
                }
                bo.RackPn = material.PartNumber;
            }
            bo.CategoryId   = type.CategoryId;
            bo.CategoryCode = category.Code;
            if (bo.Configs != null && bo.Configs.Count > 0)
            {
                bo.Configs.AsParallel().ForAll(x => x.MaterialId = bo.Id);
                ConfigRepository.Delete(x => x.MaterialId == bo.Id);
                ConfigRepository.BulkInsert(Mapper.Map <List <MaterialConfig> >(bo.Configs));
            }
            return(base.Update(bo));
        }
        public override int Delete(int?id)
        {
            if (MaterialTypeRepository.Count(x => x.CategoryId == id) > 0)
            {
                throw new BusinessException(ResponseCode.MaterialCategoryHasBeenUsed);
            }
            var configs = ConfigRepository.Delete(x => x.MaterialCategoryId == id);

            return(base.Delete(id));
        }
        public override int Update(MaterialCategoryBO vo)
        {
            var category = Repository.SingleOrDefault(x => x.Code == vo.Code);

            if (category != null && category.Id != vo.Id)
            {
                throw new BusinessException(ResponseCode.CodeAlreadyExists.Format(vo.Code));
            }
            if (vo.Configs != null && vo.Configs.Count > 0)
            {
                var cnt        = vo.Configs.Count;
                var groupCount = vo.Configs.GroupBy(x => x.ConfigKey.ToLower()).Count();
                if (cnt != groupCount)
                {
                    throw new BusinessException(ResponseCode.DuplicateKeyFoundInConfigs);
                }

                //判断是否可以修改需要容器 和自定义PN  该类别下已有物料的 不允许修改
                var materialCategory = Repository.SingleOrDefault(x => x.Id == vo.Id);
                if (materialCategory == null)
                {
                    throw new BusinessException(ResponseCode.MaterialCategoryNotExist.Format(vo.Id));
                }
                if ((materialCategory.RequireContainer != vo.RequireContainer ||
                     materialCategory.ManualPartNumber != vo.ManualPartNumber ||
                     materialCategory.RequireRack != vo.RequireRack) &&
                    MaterialRepository.Count(x => x.CategoryId == vo.Id) > 0)
                {
                    throw new BusinessException(ResponseCode.CannotModifyRequireContainerOrManualPn);
                }
                ConfigRepository.Delete(x => x.MaterialCategoryId == vo.Id);
                int sort = 10;
                foreach (var config in vo.Configs)
                {
                    config.MaterialCategoryId = vo.Id;
                    config.Id   = null;
                    config.Sort = sort;
                    sort       += 10; //步长设置为10  方便后期在中间插入
                }
                ConfigRepository.BulkInsert(Mapper.Map <List <MaterialCategoryConfig> >(vo.Configs));
            }
            return(base.Update(vo));
        }
 public async Task <bool> Delete(ParamConfigInfo param)
 {
     return(await _configRepository.Delete(param));
 }
 public override int Delete(int?id)
 {
     ConfigRepository.Delete(x => x.Id == id);
     return(base.Delete(id));
 }