示例#1
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                context.Add(genre);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Director director)
        {
            if (ModelState.IsValid)
            {
                _context.Add(director);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(director));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("Type,Value,MemberId")] MemberContact memberContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(memberContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Members"));
            }
            ViewData["InfoTypes"] = ContactInfos(memberContact.Type);
            return(View(memberContact));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("Name,Price,Year,Quantity,DirectorId,GenreId")] Dvd dvd)
        {
            if (ModelState.IsValid)
            {
                dvd.AvailableQuantity = dvd.Quantity;
                _context.Add(dvd);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DirectorId"] = new SelectList(_context.Directors, "Id", "Name", dvd.DirectorId);
            ViewData["GenreId"]    = new SelectList(_context.Genres, "Id", "Name", dvd.GenreId);
            return(View(dvd));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("DvdId,MemberId,RentTime,ReturnTime,Price")] Rent rent)
        {
            if (ModelState.IsValid)
            {
                var dvd = await _context.Dvds.FindAsync(rent.DvdId);

                dvd.AvailableQuantity = dvd.AvailableQuantity - 1;
                _context.Dvds.Update(dvd);

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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MemberId"] = new SelectList(_context.Members, "Id", "Name", rent.MemberId);
            return(View(rent));
        }