// GET: Photos/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var photo = await _context.Photos.FindAsync(id); if (photo == null) { return(NotFound()); } var model = new PhotosEditorViewModel { Photo = photo }; return(View(model)); }
public async Task <IActionResult> Create(PhotosEditorViewModel model) { if (ModelState.IsValid && model.PhotoFile != null) { _context.Photos.Add(model.Photo); await _context.SaveChangesAsync();//TODO: Возможно лишняя bool loadingResult = await LoadImage(model.Photo, model.PhotoFile); if (!loadingResult) { _context.Photos.Remove(model.Photo); await _context.SaveChangesAsync(); return(View(model)); } return(RedirectToAction(nameof(Index))); } return(View(model)); }
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)); }