Example #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="pictureID"></param>
        /// <returns></returns>
        public static DataActionStatus Delete(Guid pictureID)
        {
            SiteSettings setting = SiteSettingsManager.GetSiteSettings();
            int          index   = setting.ShowPictures.FindIndex(delegate(ShowPicture p)
            {
                return(p.ShowPictureID == pictureID);
            });

            setting.ShowPictures.RemoveAt(index);
            SiteSettingsManager.Save(setting);
            return(DataActionStatus.Success);
        }
Example #2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="picture"></param>
        /// <param name="contentStream"></param>
        /// <returns></returns>
        public static DataActionStatus Create(ShowPicture picture, Stream contentStream)
        {
            SiteSettings setting = SiteSettingsManager.GetSiteSettings();

            picture.ShowPictureID = Guid.NewGuid();
            setting.ShowPictures.Add(picture);
            SiteSettingsManager.Save(setting);

            FileStorageProvider fs = new FileStorageProvider(FileStoreKey);

            fs.AddUpdateFile("", picture.FileName, contentStream);
            return(DataActionStatus.Success);
        }
Example #3
0
        /// <summary>
        /// 更新信息
        /// </summary>
        /// <param name="picture"></param>
        /// <param name="contentStream"></param>
        /// <returns></returns>
        public static DataActionStatus Update(ShowPicture picture, Stream contentStream)
        {
            SiteSettings setting = SiteSettingsManager.GetSiteSettings();
            int          index   = setting.ShowPictures.FindIndex(delegate(ShowPicture p)
            {
                return(p.ShowPictureID == picture.ShowPictureID);
            });

            setting.ShowPictures[index] = picture;

            SiteSettingsManager.Save(setting);

            FileStorageProvider fs = new FileStorageProvider(FileStoreKey);

            fs.AddUpdateFile("", picture.FileName, contentStream);

            return(DataActionStatus.Success);
        }
        /// <summary>
        /// 获取展示图片Url
        /// </summary>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        public static string GetShowPicture(int width, int height)
        {
            string       fileName = "ad.jpg";
            SiteSettings settings = SiteSettingsManager.GetSiteSettings();

            if (!String.IsNullOrEmpty(settings.ShowPicture.Trim()))
            {
                fileName = settings.ShowPicture.Trim();
            }
            SiteFile file = SiteFiles.GetFile("ShowPicture", fileName);

            if (file == null)
            {
                using (Stream sourceStream = new FileStream(GlobalSettings.MapPath(GetDefaultShowPictureUrl()), FileMode.Open, FileAccess.Read))
                {
                    SiteFiles.AddFile(sourceStream, "ShowPicture", fileName);
                    file = SiteFiles.GetFile("ShowPicture", fileName);
                    settings.ShowPicture = string.Empty;
                    SiteSettingsManager.Save(settings);
                }
            }
            return(GetResizedImageUrl(file.File, width, height));
        }