コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("RentalID,CustomerID,CustomerName,MovieID,MovieTitle,DueDate,IsOverdue")] RentalRecordsModel rentalRecordsModel)
        {
            if (id != rentalRecordsModel.RentalID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentalRecordsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalRecordsModelExists(rentalRecordsModel.RentalID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(rentalRecordsModel));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("RentalID,MovieName,CustomerName,RentalDate,DueDate,ReturnDate")] RentalRecordsModel rentalRecordsModel)
        {
            if (id != rentalRecordsModel.RentalID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentalRecordsModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalRecordsModelExists(rentalRecordsModel.RentalID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerName"] = new SelectList(_context.Customers, "CustomerName", "Customer Name", rentalRecordsModel.CustomersModel.CustomerName);
            ViewData["MovieName"]    = new SelectList(_context.Movies, "MovieName", "Movie Name", rentalRecordsModel.MoviesModel.MovieName);
            return(View(rentalRecordsModel));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("CustomerID,MovieID,DueDate")] RentalRecordsModel rentalRecordsModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentalRecordsModel);
                var movie = await _context.Movies.SingleOrDefaultAsync(s => s.MovieID == rentalRecordsModel.MovieID);

                movie.IsCheckedOut = true;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rentalRecordsModel));
        }
コード例 #4
0
        public IActionResult CreateRecord(int movie, int customer, DateTime rentaldate, DateTime duedate)
        {
            var newRecord = new RentalRecordsModel
            {
                MovieID    = movie,
                CustomerID = customer,
                RentalDate = rentaldate,
                DueDate    = duedate
            };

            _context.RentalRecords.Add(newRecord);
            _context.SaveChanges();
            return(Redirect("Index"));
        }