コード例 #1
0
        public async Task <IActionResult> Edit(decimal id, [Bind("Id,Userid,Carid,Rentdate,Returndate,Totalprice")] Rentalhistory rentalhistory)
        {
            if (id != rentalhistory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rentalhistory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentalhistoryExists(rentalhistory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Carid"]  = new SelectList(_context.Cars, "Id", "Status", rentalhistory.Carid);
            ViewData["Userid"] = new SelectList(_context.Users, "Id", "Birthplace", rentalhistory.Userid);
            return(View(rentalhistory));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Userid,Carid,Rentdate,Returndate,Totalprice")] Rentalhistory rentalhistory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rentalhistory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Carid"]  = new SelectList(_context.Cars, "Id", "Status", rentalhistory.Carid);
            ViewData["Userid"] = new SelectList(_context.Users, "Id", "Birthplace", rentalhistory.Userid);
            return(View(rentalhistory));
        }