コード例 #1
0
        public void UpdateTopic(TopicInfo topicInfo)
        {
            string empty = string.Empty;

            try
            {
                string topImage        = topicInfo.TopImage;
                string backgroundImage = topicInfo.BackgroundImage;
                string frontCoverImage = topicInfo.FrontCoverImage;
                empty = MoveImages(topicInfo.Id, ref backgroundImage, ref topImage, ref frontCoverImage);
                List <TopicModuleInfo> topicModuleInfos = new List <TopicModuleInfo>();
                TopicModuleInfo[]      array            = topicInfo.TopicModuleInfo.ToArray();
                for (int i = 0; i < array.Length; i++)
                {
                    TopicModuleInfo topicModuleInfo  = array[i];
                    TopicModuleInfo topicModuleInfo1 = new TopicModuleInfo()
                    {
                        Name              = topicModuleInfo.Name,
                        TopicId           = topicModuleInfo.TopicId,
                        ModuleProductInfo = topicModuleInfo.ModuleProductInfo.ToList()
                    };
                    topicModuleInfos.Add(topicModuleInfo1);
                }
                //context.TopicModuleInfo.OrderBy((TopicModuleInfo item) => item.TopicId == topicInfo.Id);
                context.TopicModuleInfo.Remove <TopicModuleInfo>((TopicModuleInfo item) => item.TopicId == topicInfo.Id);
                context.SaveChanges();

                TopicInfo name = context.TopicInfo.FindById <TopicInfo>(topicInfo.Id);
                name.Name            = topicInfo.Name;
                name.BackgroundImage = backgroundImage;
                name.TopImage        = topImage;
                name.FrontCoverImage = frontCoverImage;
                name.Tags            = topicInfo.Tags;
                name.TopicModuleInfo = topicModuleInfos;
                name.IsRecommend     = topicInfo.IsRecommend;
                name.SelfDefineText  = topicInfo.SelfDefineText;
                context.SaveChanges();
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!string.IsNullOrWhiteSpace(empty))
                {
                    try
                    {
                        Directory.Delete(empty);
                    }
                    catch
                    {
                    }
                }
                throw new HimallException("修改专题失败", exception);
            }
        }
コード例 #2
0
        public JsonResult LoadProducts(long topicId, long moduleId, int page, int pageSize)
        {
            TopicInfo          topicInfo       = ServiceHelper.Create <ITopicService>().GetTopicInfo(topicId);
            TopicModuleInfo    topicModuleInfo = topicInfo.TopicModuleInfo.FirstOrDefault((TopicModuleInfo item) => item.Id == moduleId);
            IEnumerable <long> nums            =
                from item in topicModuleInfo.ModuleProductInfo.Where((ModuleProductInfo item) => {
                if (item.ProductInfo.SaleStatus != ProductInfo.ProductSaleStatus.OnSale)
                {
                    return(false);
                }
                return(item.ProductInfo.AuditStatus == ProductInfo.ProductAuditStatus.Audited);
            }).OrderBy <ModuleProductInfo, long>((ModuleProductInfo item) => item.Id).Skip(pageSize * (page - 1)).Take(pageSize)
                select item.ProductId;
            IQueryable <ProductInfo> productByIds = ServiceHelper.Create <IProductService>().GetProductByIds(nums);
            var array =
                from item in productByIds.ToArray()
                select new { name = item.ProductName, id = item.Id, image = item.GetImage(ProductInfo.ImageSize.Size_350, 1), price = item.MinSalePrice, marketPrice = item.MarketPrice };

            return(Json(array));
        }