public void AddImageToGallery() { GalleryContext db = new GalleryContext(); var unassigned = db.Images.Include(img => img.Galleries).ToArray(); var originals = unassigned.Where(img => (img is OriginalImage && img.Galleries.Count == 0)); // hard code value, take third image var galleryimage = originals.ElementAt(3); //var galleries = // new SelectList(db.Galleries.ToArray().Select(x => new { value = x.GalleryId, text = x.Name }), // "value", "text", ""); // hard coded value var galleryId = 2; if (galleryId != null) { var gallery = db.Galleries.Find(galleryId); if (gallery != null) { galleryimage.Galleries.Add(gallery); gallery.Images.Add(galleryimage); db.Entry(galleryimage).State = EntityState.Modified; db.Entry(gallery).State = EntityState.Modified; db.SaveChanges(); } } originals = unassigned.Where(img => (img is OriginalImage && img.Galleries.Count == 0)); }
public void GenerateMissingThumbs() { GalleryContext db = new GalleryContext(); var originals = from oi in db.Images.Include("ProcessedImages") where oi is OriginalImage select oi; // if I do not do this (var origList = originals.ToArray()), I get the following exception when I execute AddThumbs below: // "There is already an open DataReader associated with this Command which must be closed first." var origList = originals.ToArray(); var thumbs = from th in db.Thumbnails select th; var thumbList = thumbs.ToList(); foreach (OriginalImage orig in origList) { if (File.Exists(orig.Filename)) { orig.AddThumbs(thumbList); } else { // file does not exist, so remove from database db.Images.Remove(orig); } } db.SaveChanges(); }
public void GetOriginalImages() { GalleryContext db = new GalleryContext(); var connStr = db.Database.Connection.ConnectionString; // get the original images // var allImages = db.Images.Where(img => img is ProcessedImage); var originals = from oi in db.Images.Include("ProcessedImages") where oi is OriginalImage select oi ; foreach (var orig in originals) { } // we will foreach }
public void GetAllImages() { GalleryContext db = new GalleryContext(); var allImages = db.Images.ToList(); }
public void UpdateURLsInImages() { GalleryContext db = new GalleryContext(); foreach (var img in db.Images) { img.UrlPath = "~/GalleryImages/" + Path.GetFileName(img.Filename); foreach (var thumb in img.ProcessedImages) { thumb.UrlPath = "~/GalleryImages/" + Path.GetFileName(thumb.Filename); } } db.SaveChanges(); }
public void TestImageProcessor() { var ip = new GalleryImageProcessor(); OriginalImage img = new OriginalImage(); img.Filename = @"C:\Users\Ken\Documents\GitHub\SimplePhotoGallery\SimplePhotoGallery\Galleries\Canon1IMG_0050.JPG"; img.Title = "Renee smiling"; ip.ProcessPostUpload(img); // now we should test that we have four thumbnails: // large, medium, small and tiny GalleryContext db = new GalleryContext(); var originalImage = db.Images.ToList(); // .Where(b => b.Title.Contains("James")).ToList(); /* .FirstOrDefault(); * .Include("ProcessedImages") */ foreach (var processedImage in originalImage) { var fn = processedImage.Filename; } }
public void SetupThumbnails() { var db = new GalleryContext(); //db.Thumbnails.Where(t => t.Description == "medium"); var thumbs = from t in db.Thumbnails where t.MaxHeight == 600 select t; var tu = thumbs.First(); // var tu = db.Thumbnails.(); //Thumbnail tn = new Thumbnail(); //tn.Description = "medium"; //tn.MaxWidth = 600; //db.Thumbnails.Add(tn); //db.Thumbnails.SaveChanges(); GalleryImage master = new GalleryImage(); master.Filename = @"C:\Users\Ken\Documents\GitHub\SimplePhotoGallery\SimplePhotoGallery\Images\img_0519.jpg"; db.Images.Add(master); var mediumThumb = new ScaledImage(tu, master); // this adds the medium thumb to the ProcessedImages collection mediumThumb.Process(); // todo: add initialization code to ScaledImage to pass in BaseImage and Thumbnail //master.CreateThumbnail(tu, "medium"); db.Images.Add(mediumThumb); db.SaveChanges(); }
public void RetrieveParentImage() { // when the images are used, we need to convert the images to urls. So we should have // base filename and path in addition to extension so we can help build the url with routing // for this test we can use the file names GalleryContext db = new GalleryContext(); //db.Thumbnails.Where(t => t.Description == "medium"); //var images = from t in db.Images where t.ParentImage == null select t; var imgs = db.Images.OfType<ProcessedImage>().Where(i => i.BaseImage != null).ToList(); var xi = 1; //var testMasterImage = images.First(); }
// // GET: /GalleryDirectory/ public ActionResult Index() { // get the gallery table from the database Models.GalleryContext db = new Models.GalleryContext(); // get the originals and their thumbs // if needed they will be rotated and assigned to galleries. var picsWithouGalleries = db.Images.Where(img => img.Galleries == null && img is Models.OriginalImage); return View(picsWithouGalleries.ToList()); }