Esempio n. 1
0
 public IActionResult Edit(Movie movies)
 {
     _context.Attach(movies);
     _context.Entry(movies).State = EntityState.Modified;
     _context.SaveChanges();
     return(RedirectToAction("index"));
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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"));
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
 public async Task Edit(Movie movie)
 {
     try
     {
         _context.Attach(movie).State = EntityState.Modified;
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateException ex)
     {
         //Log the error
         throw ex;
     }
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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));
        }