/// <summary> /// Adds a photo to the datasource and return its id. /// </summary> /// <param name="navSlug"></param> /// <param name="galleryID"></param> /// <returns></returns> public int AddImage(BlogImage blogImage) { photoList.Add(new GalleryPhoto(nav) { PostGuidId = blogImage.PostGuidId, //NavSlug = navSlug, }); return photoList.Count; }
/// <summary> /// /// </summary> /// <param name="galleryID"></param> /// <param name="fileName"></param> /// <returns></returns> public int AddImage(BlogImage blogImage) { using (var db = new BlogDbContext()) { var ent = new BlogImageEntity(); ent.NavId = blogImage.Nav.NavId; ent.UserId = blogImage.UserId; ent.PostGuidId = blogImage.PostGuidId; ent.Caption = blogImage.Caption; ent.Description = blogImage.Description; db.BlogImageEntities.Add(ent); db.SaveChanges(); return ent.ImageId; } }
/// <summary> /// Returns a BlogImage object with image data/location info after adding an article image. /// </summary> /// <param name="navSlug"></param> /// <param name="postGuidId"></param> /// <param name="ext"></param> /// <param name="stream"></param> /// <returns></returns> /// <remarks> /// An image for article has only 2 sizes: /// thumb: used for Images page; /// regular: used for article /// <br /> /// When user uploads an image in ArticleEditor (it has a form points to UploadHandler.ashx), then /// the handler calls here.<br /> /// 1. AddArticleImage first inserts a record to datasource gets the imageId back;<br /> /// 2. then it lets StorageManager store the actual image file away.<br /> /// </remarks> public static BlogImage AddArticleImage(Nav nav, Guid postGuidId, string ext, Stream stream) { BlogImage blogImage = new BlogImage(nav) { PostGuidId = postGuidId, UserId = AccountManager.GetUserId(SiteContext.Current.UserName), }; int imageId = Provider.AddImage(blogImage); // save to blogImage to db, get back id string pathSegment = string.Format("fan-nav-{0}/article/{1}", nav.NavId, postGuidId); blogImage.ImageId = imageId; blogImage.UrlThumb = BlogHelper.ResizeImage(stream, BlogConfig.Image_Thumb_180, pathSegment, imageId, BlogConfig.Image_Thumb_Suffix, ext); //blogImage.UrlThumb = BlogHelper.ResizeImage(stream, BlogConfig.Image_Square_150, pathSegment, imageId, BlogConfig.Image_Thumb_Suffix, ext); blogImage.Url = BlogHelper.ResizeImage(stream, BlogConfig.Image_Large_960, pathSegment, imageId, BlogConfig.Image_Regular_Suffix, ext); return blogImage; }