Esempio n. 1
0
        public HomeCategorySet GetHomeCategorySet(int rowNumber)
        {
            if (rowNumber > 14 || rowNumber < 0)
            {
                throw new ArgumentNullException(string.Concat("行号不在取值范围内!取值必须大于0且小于", 14));
            }
            HomeCategorySet homeCategorySet = new HomeCategorySet()
            {
                RowNumber      = rowNumber,
                HomeCategories = context.HomeCategoryInfo.FindBy((HomeCategoryInfo item) => item.RowNumber == rowNumber)
            };
            HomeCategoryRowInfo homeCategoryRowInfo = context.HomeCategoryRowInfo.FindBy((HomeCategoryRowInfo item) => item.RowId == rowNumber).FirstOrDefault();
            List <HomeCategorySet.HomeCategoryTopic> homeCategoryTopics = new List <HomeCategorySet.HomeCategoryTopic>();

            HomeCategorySet.HomeCategoryTopic homeCategoryTopic = new HomeCategorySet.HomeCategoryTopic()
            {
                Url      = homeCategoryRowInfo.Url1,
                ImageUrl = homeCategoryRowInfo.Image1
            };
            homeCategoryTopics.Add(homeCategoryTopic);
            HomeCategorySet.HomeCategoryTopic homeCategoryTopic1 = new HomeCategorySet.HomeCategoryTopic()
            {
                Url      = homeCategoryRowInfo.Url2,
                ImageUrl = homeCategoryRowInfo.Image2
            };
            homeCategoryTopics.Add(homeCategoryTopic1);
            homeCategorySet.HomeCategoryTopics = homeCategoryTopics;
            return(homeCategorySet);
        }
Esempio n. 2
0
 public IEnumerable <HomeCategorySet> GetHomeCategorySets()
 {
     HomeCategorySet[] homeCategorySetArray = new HomeCategorySet[14];
     if (Cache.Get("Cache-HomeCategories") == null)
     {
         List <HomeCategoryInfo> list = (
             from C in context.HomeCategoryInfo.Include("CategoryInfo")
             select C).ToList();
         List <IGrouping <int, HomeCategoryInfo> > groupings = (
             from C in list
             group C by C.RowNumber into G
             select G).ToList <IGrouping <int, HomeCategoryInfo> >();
         foreach (IGrouping <int, HomeCategoryInfo> nums in groupings)
         {
             HomeCategorySet homeCategorySet = new HomeCategorySet()
             {
                 RowNumber      = nums.Key,
                 HomeCategories = nums
             };
             homeCategorySetArray[nums.Key - 1] = homeCategorySet;
         }
         List <HomeCategoryRowInfo> homeCategoryRowInfos = context.HomeCategoryRowInfo.FindAll <HomeCategoryRowInfo>().ToList();
         for (int i = 0; i < 14; i++)
         {
             if (homeCategorySetArray[i] == null)
             {
                 int             num = i;
                 HomeCategorySet homeCategorySet1 = new HomeCategorySet()
                 {
                     RowNumber      = i + 1,
                     HomeCategories = new List <HomeCategoryInfo>()
                 };
                 homeCategorySetArray[num] = homeCategorySet1;
             }
             List <HomeCategorySet.HomeCategoryTopic> homeCategoryTopics = new List <HomeCategorySet.HomeCategoryTopic>();
             HomeCategoryRowInfo homeCategoryRowInfo = (
                 from item in homeCategoryRowInfos
                 where item.RowId == i + 1
                 select item).FirstOrDefault();
             if (homeCategoryRowInfo != null)
             {
                 HomeCategorySet.HomeCategoryTopic homeCategoryTopic = new HomeCategorySet.HomeCategoryTopic()
                 {
                     Url      = homeCategoryRowInfo.Url1,
                     ImageUrl = homeCategoryRowInfo.Image1
                 };
                 homeCategoryTopics.Add(homeCategoryTopic);
                 HomeCategorySet.HomeCategoryTopic homeCategoryTopic1 = new HomeCategorySet.HomeCategoryTopic()
                 {
                     Url      = homeCategoryRowInfo.Url2,
                     ImageUrl = homeCategoryRowInfo.Image2
                 };
                 homeCategoryTopics.Add(homeCategoryTopic1);
             }
             homeCategorySetArray[i].HomeCategoryTopics = homeCategoryTopics;
         }
         Cache.Insert("Cache-HomeCategories", homeCategorySetArray, 5);
     }
     else
     {
         homeCategorySetArray = (HomeCategorySet[])Cache.Get("Cache-HomeCategories");
     }
     return(homeCategorySetArray);
 }
Esempio n. 3
0
        public void UpdateHomeCategorySet(int rowNumber, IEnumerable <HomeCategorySet.HomeCategoryTopic> homeCategoryTopics)
        {
            HomeCategoryRowInfo imageUrl;

            if (rowNumber > 14 || rowNumber < 0)
            {
                throw new ArgumentNullException(string.Concat("行号不在取值范围内!取值必须大于0且小于", 14));
            }
            HomeCategoryRowInfo homeCategoryRowInfo = context.HomeCategoryRowInfo.FindBy((HomeCategoryRowInfo item) => item.RowId == rowNumber).FirstOrDefault();

            imageUrl = (homeCategoryRowInfo != null ? homeCategoryRowInfo : new HomeCategoryRowInfo()
            {
                RowId = rowNumber
            });
            int num = 0;

            string[] image2 = new string[2];
            foreach (HomeCategorySet.HomeCategoryTopic list in homeCategoryTopics.ToList <HomeCategorySet.HomeCategoryTopic>())
            {
                if (string.IsNullOrWhiteSpace(list.Url) || string.IsNullOrWhiteSpace(list.ImageUrl))
                {
                    continue;
                }
                int num1 = num;
                num = num1 + 1;
                if (num1 != 0)
                {
                    if (imageUrl.Image2 != list.ImageUrl)
                    {
                        image2[1] = imageUrl.Image2;
                    }
                    imageUrl.Image2 = list.ImageUrl;
                    imageUrl.Url2   = list.Url;
                }
                else
                {
                    if (imageUrl.Image1 != list.ImageUrl)
                    {
                        image2[0] = imageUrl.Image1;
                    }
                    imageUrl.Image1 = list.ImageUrl;
                    imageUrl.Url1   = list.Url;
                }
                if (string.IsNullOrWhiteSpace(list.ImageUrl))
                {
                    continue;
                }
                TransferImages(list.ImageUrl);
            }
            if (homeCategoryRowInfo == null)
            {
                context.HomeCategoryRowInfo.Add(imageUrl);
            }
            context.SaveChanges();
            string[] strArrays = image2;
            for (int i = 0; i < strArrays.Length; i++)
            {
                string str = strArrays[i];
                if (!string.IsNullOrWhiteSpace(str))
                {
                    File.Delete(IOHelper.GetMapPath(str));
                }
            }
        }
Esempio n. 4
0
        public void UpdateHomeCategorySet(int rowNumber, IEnumerable <HomeCategorySet.HomeCategoryTopic> homeCategoryTopics)
        {
            if (rowNumber > HOME_CATEGORY_SET_COUNT || rowNumber < 0)
            {
                throw new ArgumentNullException("行号不在取值范围内!取值必须大于0且小于" + HOME_CATEGORY_SET_COUNT);
            }

            HomeCategoryRowInfo rowInfo;
            //var oldRowInfo = Context.HomeCategoryRowInfo.FindBy(item => item.RowId == rowNumber).FirstOrDefault();
            var oldRowInfo = DbFactory.Default.Get <HomeCategoryRowInfo>().Where(item => item.RowId == rowNumber).FirstOrDefault();

            if (oldRowInfo == null)
            {
                rowInfo = new HomeCategoryRowInfo()
                {
                    RowId = rowNumber
                }
            }
            ;
            else
            {
                rowInfo = oldRowInfo;
            }

            int i = 0;

            string[] needToDeleteFiles = new string[2];
            foreach (var item in homeCategoryTopics)
            {
                if (!string.IsNullOrWhiteSpace(item.Url) && !string.IsNullOrWhiteSpace(item.ImageUrl))
                {
                    if (i++ == 0)
                    {
                        if (rowInfo.Image1 != item.ImageUrl)//当图片有修改时,删除原图片
                        {
                            needToDeleteFiles[0] = rowInfo.Image1;
                        }

                        rowInfo.Image1 = item.ImageUrl;
                        rowInfo.Url1   = item.Url;
                    }
                    else
                    {
                        if (rowInfo.Image2 != item.ImageUrl)//当图片有修改时,删除原图片
                        {
                            needToDeleteFiles[1] = rowInfo.Image2;
                        }

                        rowInfo.Image2 = item.ImageUrl;
                        rowInfo.Url2   = item.Url;
                    }
                    if (!string.IsNullOrWhiteSpace(item.ImageUrl))
                    {
                        TransferImages(item.ImageUrl);
                    }
                }
            }
            if (oldRowInfo == null)
            {
                //Context.HomeCategoryRowInfo.Add(rowInfo);
                DbFactory.Default.Add(rowInfo);
            }
            //Context.SaveChanges();

            //删除原图片
            foreach (var file in needToDeleteFiles)
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    HimallIO.DeleteFile(file);
                }
            }
        }