Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("GalleryEntryID,ImageID")] GalleryEntry_Image galleryEntry_Image)
        {
            if (id != galleryEntry_Image.ImageID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(galleryEntry_Image);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GalleryEntry_ImageExists(galleryEntry_Image.ImageID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["GalleryEntryID"] = new SelectList(_context.GalleryEntries, "GalleryEntryID", "GalleryEntryID", galleryEntry_Image.GalleryEntryID);
            ViewData["ImageID"]        = new SelectList(_context.Images, "ImageID", "ImageID", galleryEntry_Image.ImageID);
            return(View(galleryEntry_Image));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("GalleryEntryID,ImageID")] GalleryEntry_Image galleryEntry_Image)
        {
            if (ModelState.IsValid)
            {
                _context.Add(galleryEntry_Image);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["GalleryEntryID"] = new SelectList(_context.GalleryEntries, "GalleryEntryID", "GalleryEntryID", galleryEntry_Image.GalleryEntryID);
            ViewData["ImageID"]        = new SelectList(_context.Images, "ImageID", "ImageID", galleryEntry_Image.ImageID);
            return(View(galleryEntry_Image));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Compute the thumbnail url for a particular gallery entry
 /// </summary>
 /// <param name="galleryEntry">The gallery entry whose thumbnail you want to compute
 /// Note: The collection navigation property "Images" needs to be set on this GalleryEntry instance
 /// </param>
 /// <returns>A string which is the thumbnail as a URL</returns>
 public string ComputeThumbnail(GalleryEntry galleryEntry)
 {
     if (galleryEntry.Images.Count() == 0)
     {
         // if this gallery entry has no images defined, return a random stock photo
         return("/images/no-image.png");
         // return "https://unsplash.it/g/200/300/?random";
     }
     else
     {
         // get first related entry in the associative many2many table
         GalleryEntry_Image firstImage = galleryEntry.Images.First();
         return(firstImage.Image.Url);
     }
 }