public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,DateOfBirth")] Author author) { if (ModelState.IsValid) { _context.Add(author); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Create([Bind("GenreID,GenreTypes,Description")] Genre genre) { if (ModelState.IsValid) { _context.Add(genre); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["GenreTypes"] = new SelectList(GetGenreTypes(), "Id", "Value"); return(View(genre)); }
public async Task <IActionResult> CreateUser(Author newUser) { if (Users.Users.Any(e => e.Username == newUser.Username)) { Console.WriteLine($"POST /users/create <400> {DateTime.Now}"); return(BadRequest("username taken")); } Console.WriteLine($"POST /users/create <200> {newUser.Username} {DateTime.Now}"); Users.Add(newUser); await Users.SaveChangesAsync(); return(Ok(newUser)); }
public async Task <IActionResult> Create([Bind("AuthorBooksID,AuthorID,BookTitleID")] AuthorBooks authorBooks) { if (ModelState.IsValid) { _context.Add(authorBooks); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["AuthorID"] = new SelectList(_context.Authors.OrderBy(a => a.FirstName), "AuthorID", "FirstName", authorBooks.AuthorID); ViewData["BookTitleID"] = new SelectList(_context.BookTitles.OrderBy(b => b.Title), "BookTitleID", "Title", authorBooks.BookTitleID); return(View(authorBooks)); }
public async Task <IActionResult> Create([Bind("BookTitleGenresID,GenreID,BookTitleID")] BookTitleGenres bookTitleGenres) { if (ModelState.IsValid) { _context.Add(bookTitleGenres); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["BookTitleID"] = new SelectList(_context.BookTitles, "BookTitleID", "BookTitleID", bookTitleGenres.BookTitleID); ViewData["GenreID"] = new SelectList(_context.Genres, "GenreID", "GenreID", bookTitleGenres.GenreID); return(View(bookTitleGenres)); }
public void Create(BookTitle bookTitle) { _context.Add(bookTitle); _context.SaveChanges(); }
private static void SetupDB() { Genre fantasy = new Genre { Name = "Fantasy" }; Genre urban = new Genre { Name = "Urban" }; Genre superheroes = new Genre { Name = "Superheroes" }; Genre scifi = new Genre { Name = "Scifi" }; Genre magic = new Genre { Name = "Magic" }; Book b1 = new() { Title = "Rythm of War", PageCount = 1232, PublicationYear = 2020, ISBN = "0765326388", Genres = new List <Genre> { fantasy, magic } }; Book b2 = new() { Title = "The Alloy of Law", PageCount = 332, PublicationYear = 2011, ISBN = "0765330423", Genres = new List <Genre> { urban, fantasy, magic } }; Book b3 = new() { Title = "Steelheart", PageCount = 386, PublicationYear = 2013, ISBN = "0385743564", Genres = new List <Genre> { superheroes, urban, scifi } }; Book b4 = new() { Title = "Judgment of Mars", PageCount = 270, PublicationYear = 2017, ISBN = "34538192", Genres = new List <Genre> { scifi, fantasy, magic } }; Book b5 = new() { Title = "Blood of the Innocent", PageCount = 322, PublicationYear = 2017, ISBN = "35823660", Genres = new List <Genre> { urban, fantasy } }; Author brandon = new Author { FirstName = "Brandon", LastName = "Sanderson", Address = new() { Street = "Nowhere", HouseNumber = 3, PostCode = 837 }, Books = new List <Book> { b1, b2, b3 } }; Author glynn = new Author { FirstName = "Glynn", LastName = "Stewart", Address = new() { Street = "Anywhere", HouseNumber = 7, PostCode = 824 }, Books = new List <Book> { b4, b5 } }; using AuthorContext ac = new AuthorContext(); ac.Add(brandon); ac.Add(glynn); ac.SaveChanges(); } } }
public void Create(Author author) { _context.Add(author); _context.SaveChanges(); }
public void Create(Reviews review) { _context.Add(review); _context.SaveChanges(); }