Exemple #1
0
        public void AddMobileHomeTopic(long topicId, long shopId, PlatformType platformType, string frontCoverImage = null)
        {
            var existTopicInfo = Context.MobileHomeTopicsInfo.Count(item => item.TopicId == topicId && item.ShopId == shopId && item.Platform == platformType);

            if (existTopicInfo > 0)
            {
                throw new Himall.Core.HimallException("已经添加过相同的专题");
            }

            var allCount = Context.MobileHomeTopicsInfo.Count(item => item.ShopId == shopId && item.Platform == platformType);

            if (allCount >= MAX_HOMETOPIC_COUNT)
            {
                throw new Himall.Core.HimallException(string.Format("最多只能添加{0}个专题", MAX_HOMETOPIC_COUNT));
            }

            var mobileHomeTopicInfo = new MobileHomeTopicsInfo()
            {
                Platform = platformType,
                ShopId   = shopId,
                TopicId  = topicId,
            };

            Context.MobileHomeTopicsInfo.Add(mobileHomeTopicInfo);
            Context.SaveChanges();
        }
Exemple #2
0
        public void AddMobileHomeTopic(long topicId, long shopId, PlatformType platformType, string frontCoverImage = null)
        {
            if (context.MobileHomeTopicsInfo.Count((MobileHomeTopicsInfo item) => item.TopicId == topicId && item.ShopId == shopId && (int)item.Platform == (int)platformType) > 0)
            {
                throw new HimallException("已经添加过相同的专题");
            }
            if (context.MobileHomeTopicsInfo.Count((MobileHomeTopicsInfo item) => item.ShopId == shopId && (int)item.Platform == (int)platformType) >= 10)
            {
                throw new HimallException(string.Format("最多只能添加{0}个专题", 10));
            }
            MobileHomeTopicsInfo mobileHomeTopicsInfo = new MobileHomeTopicsInfo()
            {
                Platform = platformType,
                ShopId   = shopId,
                TopicId  = topicId
            };

            context.MobileHomeTopicsInfo.Add(mobileHomeTopicsInfo);
            context.SaveChanges();
        }