public async Task <IActionResult> Create([Bind("Id,Title")] Collection collection)
        {
            if (ModelState.IsValid)
            {
                _context.Add(collection);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(collection));
        }
        public async Task <IActionResult> Create([Bind("id,name")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Book book)
        {
            if (ModelState.IsValid)
            {
                _db.Add(book);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("Id,CustomerID,Title,Author,BorrowDate,ReturnDate,BooksAmount")] Books books)
        {
            if (ModelState.IsValid)
            {
                _context.Add(books);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }
        public async Task <IActionResult> Create(Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("Id,Title,Author,Description")] 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,Title,ReleaseDate,Genre,Price,Rating")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Beispiel #8
0
        public async Task <IActionResult> Create([Bind("Title,Id,Description,BookId")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
        // Pitfall #1: using Task.Run() on the server
        //private Task<int> GetBookPages()
        //{
        //    return Task.Run(() =>
        //    {
        //        _logger.LogInformation($"ThreadId when calculating the amount of pages: {System.Threading.Thread.CurrentThread.ManagedThreadId}");

        //        var pageCalculator = new Books.Legacy.ComplicatedPageCalculator();
        //        return pageCalculator.CalculateBookPages();
        //    });



        public void AddBook(Book bookToAdd)
        {
            if (bookToAdd == null)
            {
                throw new ArgumentNullException(nameof(bookToAdd));
            }
            //await _context.AddAsync(bookToAdd);/*use async only to allow special value generators, such as the one
            //     used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo',
            //     to access the database asynchronously. For all other cases the non async method
            //     should be used.so in this case the moment we add but it will track the entity.so use async only when u use database*/
            _context.Add(bookToAdd);
        }
Beispiel #10
0
        public async Task <IActionResult> Create([Bind("Id,Content,BookId")] Review review)
        {
            if (ModelState.IsValid)
            {
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"] = new SelectList(_context.Book, "Id", "Id", review.BookId);
            return(View(review));
        }
        public async Task <IActionResult> Create([Bind("id,userId")] ReadingCard readingCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(readingCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["userId"] = new SelectList(_context.User, "id", "id", readingCard.userId);
            return(View(readingCard));
        }
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,DateOfBirth,Mobile,Address,City,Province,Country,PostalCode")] UserProfileModel userProfileModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userProfileModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Create)));
                // return RedirectToAction(nameof(SecondHandBook.Controllers.HomeController.Index));
            }
            return(View(userProfileModel));
        }
Beispiel #13
0
        public async Task <IActionResult> Create([Bind("BookId,UserId,Rating")] UserBook userBook)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userBook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"] = new SelectList(_context.Books, "Id", "Author", userBook.BookId);
            return(View(userBook));
        }
Beispiel #14
0
        public async Task <IActionResult> Create([Bind("Id,Isbn")] Book books)
        {
            if (ModelState.IsValid)
            {
                books.Id = Guid.NewGuid();
                _context.Add(books);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(books));
        }
        public static void PopulateDatabase()
        {
            using var context = new BooksContext();

            context.Add(
                new Book()
            {
                Isbn = "978-0-39-481823-8", Title = "What Do People Do All Day?"
            });

            context.SaveChanges();
        }
Beispiel #16
0
        public async Task <IActionResult> Create([Bind("Id,Title,AuthorId")] Comics comics)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comics);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"] = new SelectList(_context.Author, "Id", "Id", comics.AuthorId);
            return(View(comics));
        }
        public async Task <IActionResult> Create([Bind("Id,GenreId,BookId")] BooksGenres booksGenres)
        {
            if (ModelState.IsValid)
            {
                _context.Add(booksGenres);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"]  = new SelectList(_context.Book, "Id", "Id", booksGenres.BookId);
            ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Id", booksGenres.GenreId);
            return(View(booksGenres));
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            var booksContext = new BooksContext();

            booksContext.Add(new Book()
            {
                Title = "Mein erstes Buch", BookId = 1, Publisher = "Selbstpublizierer"
            });
            booksContext.Add(new Book()
            {
                Title = "Mein zweites Buch", BookId = 2, Publisher = "Pakito"
            });
            booksContext.Add(new Book()
            {
                Title = "Mein drittes Buch", BookId = 3, Publisher = "Pako"
            });
            booksContext.Add(new Book()
            {
                Title = "Mein viertes Buch", BookId = 4, Publisher = "Selbstpublizierer"
            });
            booksContext.SaveChanges();
        }
Beispiel #19
0
        public async Task <IActionResult> Create([Bind("id,name,description,imageUrl,genres,authorId,posterId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["authorId"] = new SelectList(_context.Author, "id", "id", book.authorId);
            ViewData["posterId"] = new SelectList(_context.Poster, "id", "id", book.posterId);
            return(View(book));
        }
Beispiel #20
0
        public async Task <IActionResult> Create([Bind("Id,Name,AuthorId,CollectionId,Year,GenreId")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorId"]     = new SelectList(_context.Author, "Id", "Id", book.AuthorId);
            ViewData["CollectionId"] = new SelectList(_context.Collection, "Id", "Id", book.CollectionId);
            return(View(book));
        }
Beispiel #21
0
        public async Task <IActionResult> Create(Two twoR)
        {
            if (ModelState.IsValid)
            {
                twoR.Book.Author = _context.Author.Where(r => r.ID == twoR.Book.AuthorRefId).SingleOrDefault();
                _context.Add(twoR.Book);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            Two two = new Two();

            two.Authors = _context.Author.ToList();
            two.Book    = twoR.Book;
            return(View(two));
        }
Beispiel #22
0
        public async Task <IActionResult> CreateAsync([FromBody] Autores autor)
        {
            if (ModelState.IsValid)
            {
                var _autor = new Autores()
                {
                    Nombre    = autor.Nombre,
                    Apellidos = autor.Apellidos
                };

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

                return(StatusCode((int)HttpStatusCode.Created, _autor));
            }
            else
            {
                return(BadRequest());
            }
        }
    public static void Collections_and_dictionaries_of_primitive_types()
    {
        Console.WriteLine($">>>> Sample: {nameof(Collections_and_dictionaries_of_primitive_types)}");
        Console.WriteLine();

        Helpers.RecreateCleanDatabase();

        #region Insert
        using var context = new BooksContext();

        var book = new Book
        {
            Title  = "How It Works: Incredible History",
            Quotes = new List <string>
            {
                "Thomas (Tommy) Flowers was the British engineer behind the design of the Colossus computer.",
                "Invented originally for Guinness, plastic widgets are nitrogen-filled spheres.",
                "For 20 years after its introduction in 1979, the Walkman dominated the personal stereo market."
            },
            Notes = new Dictionary <string, string>
            {
                { "121", "Fridges" },
                { "144", "Peter Higgs" },
                { "48", "Saint Mark's Basilica" },
                { "36", "The Terracotta Army" }
            }
        };

        context.Add(book);
        context.SaveChanges();
        #endregion

        #region Updates
        book.Quotes.Add("Pressing the emergency button lowered the rods again.");
        book.Notes["48"] = "Chiesa d'Oro";

        context.SaveChanges();
        #endregion

        Console.WriteLine();
    }
Beispiel #24
0
        public async Task <IActionResult> CreateAsync([FromBody] Libros libro)
        {
            if (ModelState.IsValid)
            {
                var _libro = new Libros()
                {
                    Titulo        = libro.Titulo,
                    Sinopsis      = libro.Sinopsis,
                    NPaginas      = libro.NPaginas,
                    EditorialesId = libro.EditorialesId
                };

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

                return(StatusCode((int)HttpStatusCode.Created, _libro));
            }
            else
            {
                return(BadRequest());
            }
        }
 public string Insert(T item)
 {
     booksContext.Add(item);
     return(" added...");
 }
Beispiel #26
0
 public void AddBook(Book book)
 {
     context.Add(book);
     context.SaveChanges();
 }
Beispiel #27
0
 public void Create(Book item)
 {
     db.Add(item);
 }
Beispiel #28
0
        public void AddBook(Book book)
        {
            book.Id = Guid.NewGuid();

            _context.Add(book);
        }