コード例 #1
0
        public async Task <IActionResult> Create([Bind("PublisherId,Name")] Publisher publisher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(publisher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(publisher));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("UserId,FirstName,LastName,PhoneNumber,Email,Address")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Periodicity,Number,Id,Title,Quantity,Year,Edition")] Magazine magazine)
        {
            if (ModelState.IsValid)
            {
                _context.Add(magazine);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(magazine));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Author,Genre,Id,Title,Quantity,Year,Edition")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("BookId,ISBN,Title,AuthorId,PublisherId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"]    = new SelectList(_context.Author, "AuthorId", "Name", book.AuthorId);
            ViewData["PublisherId"] = new SelectList(_context.Set <Publisher>(), "PublisherId", "Name", book.PublisherId);
            return(View(book));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("RentalId,RentalDate,ReturnDate,BookId,UserId")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                if (_context.Rental.Any(p => p.ReturnDate == null && p.BookId == rental.BookId))
                {
                    TempData["FlashMessage"] = "This book is currently rented out!";

                    return(RedirectToAction(nameof(Index)));
                }

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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"] = new SelectList(_context.Book, "BookId", "Title", rental.BookId);
            ViewData["UserId"] = new SelectList(_context.User, "UserId", "Name", rental.UserId);

            return(View(rental));
        }
コード例 #7
0
        public void Add(Librarian entity)
        {
            var response = librarianContext.Add(entity);

            librarianContext.SaveChanges();
        }