예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,Processed,RawUrl,ProcessedUrl")] Photo photo)
        {
            if (id != photo.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(photo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhotoExists(photo.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(photo));
        }
예제 #2
0
        public static void ProcessImage(int photoId, string rootPath)
        {
            Thread.Sleep(5000);

            using (var db = new MvcPhotoContext())
            {
                var photo = db.Find <Photo>(photoId);
                var savedImageFullPath = Path.Combine(Path.Combine(rootPath, photo.RawUrl));
                var processedFullPath  = Path.Combine(Path.Combine(rootPath, photo.ProcessedUrl));


                using (Image <Rgba32> image = Image.Load(savedImageFullPath))
                {
                    image.Mutate(ctx => ctx.Polaroid());

                    image.Save(processedFullPath); // Automatic encoder selected based on extension.
                }

                photo.Processed = true;
                db.Update(photo);
                db.SaveChanges();
            }
        }