Exemplo n.º 1
0
        public async Task <IActionResult> Edit(SmartFuture smartFuture)
        {
            if (!ModelState.IsValid)
            {
                return(View(smartFuture));
            }
            var smartfutureDb = await _context.SmartFutures.FindAsync(smartFuture.Id);

            if (smartFuture.Photo != null)
            {
                try
                {
                    var newPhoto = await smartFuture.Photo.SaveFileAsync(_env.WebRootPath, "images");

                    IFormFileExstensions.Delete(_env.WebRootPath, "images", smartfutureDb.Image);

                    smartfutureDb.Image = newPhoto;
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(smartFuture));
                }
            }

            smartfutureDb.Title    = smartFuture.Title;
            smartfutureDb.Subtitle = smartFuture.Subtitle;
            smartfutureDb.Button   = smartFuture.Button;


            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SmartFuture smartFuture = await _context.SmartFutures.FindAsync(id);

            if (smartFuture == null)
            {
                return(NotFound());
            }

            return(View(smartFuture));
        }