public async Task <IActionResult> Edit(int id, PhotosEditorViewModel model) { if (id != model.Photo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (model.PhotoFile != null) { bool loadingResult = await LoadImage(model.Photo, model.PhotoFile); if (!loadingResult) { return(View(model.Photo)); } } _context.Update(model.Photo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhotoExists(model.Photo.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }