コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("RentalId,MovieId,CustomerId,RentalDate,DueDate,ReturnDate")] RentalRecordModel rentalRecordModel)
        {
            if (id != rentalRecordModel.RentalId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentalRecordModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalRecordModelExists(rentalRecordModel.RentalId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "CustomerId", rentalRecordModel.CustomerId);
            ViewData["MovieId"]    = new SelectList(_context.Movies, "MovieId", "MovieId", rentalRecordModel.MovieId);
            return(View(rentalRecordModel));
        }
コード例 #2
0
ファイル: Customers.cs プロジェクト: OptionSelect/DotnetVideo
        public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,CustomerPhoneNumber")] CustomerModel customerModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customerModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customerModel));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("MovieId,MovieName,MovieDescription,GenreId")] MovieModel movieModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GenreId"] = new SelectList(_context.Genres, "GenreId", "GenreId", movieModel.GenreId);
            return(View(movieModel));
        }
コード例 #4
0
        public async Task <IActionResult> CheckIn(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var rentalRecordModel = await _context.RentalRecords.SingleOrDefaultAsync(m => m.RentalId == id);

            if (rentalRecordModel == null)
            {
                return(NotFound());
            }
            rentalRecordModel.ReturnDate = DateTime.Now;
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }