Esempio n. 1
0
        public MoviesViewModel CheckoutMovie(int movieId, string userName)
        {
            var movie = GetMovie(movieId);
            var user  = _context.Users.FirstOrDefault(u => u.UserName == userName);

            var com = new CheckedOutMovies()
            {
                User    = user,
                UserId  = user.Id,
                Movie   = movie,
                MovieId = movieId,
                DueDate = DateTime.Now.AddDays(4)
            };

            _context.Add(com);
            _context.SaveChanges();

            var mvm = new MoviesViewModel()
            {
                Movie            = movie,
                CheckedOutMovies = com
            };

            return(mvm);
        }
Esempio n. 2
0
        public async Task <IActionResult> Checkin(CheckedOutMovies checkedOutMovie)
        {
            var returnMovie = await _context.CheckedOutMovie.FirstOrDefaultAsync(m => m.Id == checkedOutMovie.Id);

            _context.CheckedOutMovie.Remove(returnMovie);
            await _context.SaveChangesAsync();

            return(RedirectToAction("CheckedOutMovie", "Movie"));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(int?id)
        {
            var comovies = new CheckedOutMovies();

            if (ModelState.IsValid)
            {
                comovies.DueDate    = DateTime.Today.AddDays(14);
                ViewData["DueDate"] = comovies.DueDate;
                comovies.UserID     = HttpContext.User.Identity.Name;
                comovies.MovieID    = (int)id;
                //ApplicationUser currentUser = _context.Users.FirstOrDefault(x => x.Id == User.Identity.GetUserId());
                _context.CheckedOutMovies.Add(comovies);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Result)));
            }
            return(View(comovies));
        }
Esempio n. 4
0
        public async Task <IActionResult> CheckoutMovie(Movie movie)
        {
            var userId        = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var dueDate       = DateTime.Now.AddDays(7).Date;
            var checkoutMovie = new CheckedOutMovies()
            {
                UserId  = userId,
                DueDate = dueDate,
                MovieId = movie.Id
            };

            _context.CheckedOutMovie.Add(checkoutMovie);
            await _context.SaveChangesAsync();

            var checkOutMovie = new MovieListAndCheckout
            {
                MovieTitle   = movie.Title,
                MovieDueDate = checkoutMovie.DueDate
            };

            TempData["CheckedOutMovie"] = JsonConvert.SerializeObject(checkOutMovie);

            return(RedirectToAction("Result", "Movie"));
        }