public IEnumerable <Author> Get() { using (var context = new BookStoresContext()){ //Get All Authors // return context.Author.ToList(); // return context.Author.Where(a => a.AuthorId == 1).ToList(); //Add an Author //Author author = new Author(); //author.FirstName = "Abdullah"; //author.LastName = "Qureshi"; //context.Author.Add(author); //context.SaveChanges(); //return context.Author.Where(a => a.FirstName == "Abdullah").ToList(); //Update an Author //Author author = context.Author.Where(a => a.FirstName == "Abdullah").FirstOrDefault(); //author.Phone = "777-777-7777"; //context.SaveChanges(); // return context.Author.Where(a => a.FirstName == "Abdullah").ToList(); //Delete an Author Author author = context.Authors.Where(a => a.FirstName == "Abdullah").FirstOrDefault(); context.Authors.Remove(author); context.SaveChanges(); return(context.Authors.Where(a => a.FirstName == "Abdullah").ToList()); } }
public IActionResult PostPublisherDetails() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var publisher = new Publisher { PublisherName = "Tom Cruise", State = "NY", Country = "USA", City = "New York" }; var book1 = new Book { Title = "Sushi, Anyone?", PublishedDate = DateTime.Now }; var book2 = new Book { Title = "Sushi2, Anyone?", PublishedDate = DateTime.Now }; var sales1 = new Sale { Quantity = 10, StoreId = "6380", PayTerms = "Net 60", OrderNum = "6871", OrderDate = DateTime.Now, }; var sales2 = new Sale { Quantity = 20, StoreId = "6380", PayTerms = "Net 61", OrderNum = "6872", OrderDate = DateTime.Now, }; book1.Sales.Add(sales1); book2.Sales.Add(sales2); publisher.Books.Add(book1); publisher.Books.Add(book2); _context.Publishers.Add(publisher); _context.SaveChanges(); if (publisher == null) { return(NotFound()); } return(Ok(publisher)); }