public IActionResult Edit(Movie movies) { _context.Attach(movies); _context.Entry(movies).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("index")); }
public static void EditSeriesAndSeasonAfterDeleteEpisode(MovieContext _ctx, Series series, Season season) { _ctx.Attach(series); series.Series_EpisodeCount--; series.UpdatedAt = DateTime.Now; _ctx.Attach(season); season.Season_EpisodeCount--; season.UpdatedAt = DateTime.Now; _ctx.SaveChanges(); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_context.Movie.Any(e => e.ID == Movie.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var movie = MovieModel.ToMovie(); _context.Attach(movie).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieExists(movie.Id)) { return(NotFound()); } throw; } return(RedirectToPage("./Index")); }
public void AlterFilmItemAverage(FilmItem filmItem, int rating) { _context.Attach(filmItem); if (filmItem.VoteCount == null && filmItem.VoteAverage == null) { filmItem.VoteCount = 1; filmItem.VoteAverage = rating; } else { var totalRating = filmItem.VoteAverage * filmItem.VoteCount; filmItem.VoteCount++; filmItem.VoteAverage = (totalRating + rating) / filmItem.VoteCount; } filmItem.UpdatedAt = DateTime.Now; _context.SaveChanges(); }
public async Task Edit(Movie movie) { try { _context.Attach(movie).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (DbUpdateException ex) { //Log the error throw ex; } }
public async Task <IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (user == null) { throw new ArgumentNullException(nameof(user)); } _context.Attach(user).State = EntityState.Modified; return(await _context.SaveChangesAsync() == 0 ? IdentityResult.Failed(new IdentityError() { Description = $"Could not insert user {user.Email}." }) : IdentityResult.Success); }
public async Task <IActionResult> Edit(int id, [Bind("CourseID,Title,Credits,DepartmentID")] Course course) { if (id != course.CourseId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Attach(course).State = EntityState.Modified; //_context.Update(course); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.CourseId)) { return(NotFound()); } else { throw; } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } return(RedirectToAction(nameof(Index))); } PopulateDepartmentsDropDownList(course.DepartmentId); return(View(course)); }