Ejemplo n.º 1
0
        public void AddBook(Book book, string authorFullName)
        {
            var author = booksDbContext.Add <Author>(new Author()
            {
                FullName = authorFullName
            });

            booksDbContext.SaveChanges();
            book.AuthorId = author.Entity.Id;
            booksDbContext.Add <Book>(book);
        }
Ejemplo n.º 2
0
 public void AddBook(Book booktoAdd)
 {
     if (booktoAdd == null)
     {
         throw new ArgumentNullException(nameof(booktoAdd));
     }
     _context.Add(booktoAdd);
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Title,Author,ISBN,LoanedTo")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
        public async Task <IActionResult> Create([Bind("Id,タイトル,著者,出版社,発行日,分野,リンク")] Books books)
        {
            if (ModelState.IsValid)
            {
                _context.Add(books);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("BookId,Title,AuthorId")] 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);
            return(View(book));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("AuthorId,MyProperty")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                ViewBag.Title   = "Author added successfully";
                ViewBag.Message = "New author created successfully!";
                return(View("Success"));
            }
            return(View(author));
        }
Ejemplo n.º 8
0
        [ValidateAntiForgeryToken]                                                      //validacao de seguranca
        public async Task <IActionResult> Create([Bind("AuthorId,Name")] Author author) //serve para evitar alguns ataques, só recebo os campos que estão no bind
        {
            if (ModelState.IsValid)
            {
                //todo: validacoes adicionais antes de inserir o autor
                _context.Add(author);
                await _context.SaveChangesAsync();

                //todo: informar o user, autor criado com sucesso
                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Ejemplo n.º 9
0
        public async Task Post([FromBody] Book book)
        {
            _dataContext.Add(book);

            await _dataContext.SaveChangesAsync();
        }