public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Year,Director,PathImg")] Film film, IFormFile uploadedFile) { if (id != film.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (uploadedFile != null) { string path = "/img/" + uploadedFile.FileName; using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } film.PathImg = path; } film.UserId = Request.Form["UserID"]; await _film.Edit(film); } catch (DbUpdateConcurrencyException) { if (!FilmExists(film.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(film)); }
public ActionResult Edit(FilmEditViewModel model) { InitEditViewBag(); if (ModelState.IsValid) { try { model.UserId = User.Identity.GetUserId(); var result = filmSrv.Edit(model); if (result != null && result.Id > 0) { SavePoster(model.Files, result.Id); } return(Redirect("~/profile")); } catch { ModelState.AddModelError("", "При редактировании произошли ошибки!"); } } return(View(model)); }