Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserId,MovieId,DueDate")] CheckedOutMovies checkedOutMovies)
        {
            if (id != checkedOutMovies.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(checkedOutMovies);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CheckedOutMoviesExists(checkedOutMovies.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MovieId"] = new SelectList(_context.Movies, "ID", "ID", checkedOutMovies.MovieId);
            ViewData["UserId"]  = new SelectList(_context.Users, "Id", "Id", checkedOutMovies.UserId);
            return(View(checkedOutMovies));
        }
Example #2
0
        public async Task <IActionResult> CheckOut(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var movie = await _context.Movies
                        .FirstOrDefaultAsync(m => m.ID == id);

            if (movie == null)
            {
                return(NotFound());
            }
            var user             = HttpContext.User;
            var checkedOutMovies = new CheckedOutMovies()
            {
                DueDate = DateTime.Now.AddDays(2),
                MovieId = movie.ID,
                UserId  = user.Identity.Name
            };

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

            return(View(checkedOutMovies));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Id,UserId,MovieId,DueDate")] CheckedOutMovies checkedOutMovies)
        {
            if (ModelState.IsValid)
            {
                _context.Add(checkedOutMovies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MovieId"] = new SelectList(_context.Movies, "ID", "ID", checkedOutMovies.MovieId);
            ViewData["UserId"]  = new SelectList(_context.Users, "Id", "Id", checkedOutMovies.UserId);
            return(View(checkedOutMovies));
        }