Ejemplo n.º 1
0
        public void SaveBusinessCategory(long id, decimal commisRate)
        {
            if (commisRate > new decimal(100))
            {
                throw new InvalidPropertyException("分佣比例不能大于100");
            }
            if (commisRate < new decimal(0))
            {
                throw new InvalidPropertyException("分佣比例不能小于0");
            }
            BusinessCategoryInfo businessCategoryInfo = context.BusinessCategoryInfo.FirstOrDefault((BusinessCategoryInfo item) => item.Id == id);

            if (businessCategoryInfo == null)
            {
                throw new HimallException(string.Concat("未找到", id, "对应的经营类目"));
            }
            businessCategoryInfo.CommisRate = commisRate;
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void SaveBusinessCategory(long id, Dictionary <long, decimal> bCategoryList)
        {
            IQueryable <BusinessCategoryInfo> businessCategoryInfos = context.BusinessCategoryInfo.FindBy((BusinessCategoryInfo b) => b.ShopId.Equals(id));

            foreach (BusinessCategoryInfo list in businessCategoryInfos.ToList())
            {
                context.BusinessCategoryInfo.Remove(list);
            }
            foreach (KeyValuePair <long, decimal> keyValuePair in bCategoryList)
            {
                DbSet <BusinessCategoryInfo> businessCategoryInfo  = context.BusinessCategoryInfo;
                BusinessCategoryInfo         businessCategoryInfo1 = new BusinessCategoryInfo()
                {
                    CategoryId = keyValuePair.Key,
                    CommisRate = keyValuePair.Value,
                    ShopId     = id
                };
                businessCategoryInfo.Add(businessCategoryInfo1);
            }
            context.SaveChanges();
        }