예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Sinopsis,Genre,Image,Rented")] Film film)
        {
            if (id != film.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(film);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FilmExists(film.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(film));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,LastName,Email,ProfilePicture")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
예제 #3
0
        public async Task <IActionResult> Rent(int filmId)
        {
            Film rentedFilm = await _context.Film.FindAsync(filmId);

            rentedFilm.Rented = true;
            _context.Update(rentedFilm);
            await _context.SaveChangesAsync();

            UserFilm newRent = new UserFilm()
            {
                DateRental = DateTime.Now,
                Film       = rentedFilm,
                User       = await _context.User.FindAsync(1)
            };

            _context.Add(newRent);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }