GetTopPhotosForGallery() public method

public GetTopPhotosForGallery ( int galleryId ) : IList
galleryId int
return IList
Beispiel #1
0
        public ActionResult Thumbnail(int id)
        {
            var db = new PhotoGalleryRepository();

            var gallery = db.GetGallery(id);
            if (gallery == null)
            {
                return HttpNotFound();
            }

            var photos = db.GetTopPhotosForGallery(id);
            if (photos.Count == 0)
            {
                return File(Server.MapPath("~/Content/Images/gallery-empty.png"), "image/jpeg");
            }

            using (var generator = new MultiThumbnailGenerator())
            {
                foreach (var photo in photos)
                {
                    using (var imageStream = new MemoryStream(photo.FileContents))
                    {
                        using (var image = System.Drawing.Image.FromStream(imageStream))
                        {
                            generator.AddImage(image);
                        }
                    }
                }
                using (var outStream = new MemoryStream())
                {
                    generator.WritePngToStream(outStream);
                    var image = new WebImage(outStream);
                    image.Write();

                    return null;
                }
            }
        }