public IEnumerable <Author> Get()
        {
            using (var _context = new BookStoresDBContext())  // Instans
            {
                //get all authors
                //return context.Author.ToList();

                // add an author in my database
                //Author author = new Author(); // add an author in my database
                //author.FirstName = "John"; // add an author in my database
                //author.LastName = "Smith"; // add an author in my database

                //context.Author.Add(author); // add an author in my database

                Author author = _context.Author.Where(auth => auth.FirstName == "John").FirstOrDefault();
                author.Phone = "777-777-7777";

                _context.SaveChanges(); // add an author in my database



                // get author by id
                return(_context.Author.Where(auth => auth.FirstName == "John").ToList());
            }
        }
Exemple #2
0
        public async Task <ActionResult <Publisher> > PostPublisherDetails()
        {
            var publisher = new Publisher();

            publisher.PublisherName = "Harper & Brothers";
            publisher.City          = "New York City";
            publisher.State         = "NY";
            publisher.Country       = "USA";

            Book book1 = new Book();

            book1.Title         = "Good night moon - 1";
            book1.PublishedDate = DateTime.Now;

            Book book2 = new Book();

            book2.Title         = "Good night moon - 2";
            book2.PublishedDate = DateTime.Now;

            Sale sale1 = new Sale();

            sale1.Quantity  = 2;
            sale1.StoreId   = "8042";
            sale1.OrderNum  = "XYZ";
            sale1.PayTerms  = "Net 30";
            sale1.OrderDate = DateTime.Now;

            Sale sale2 = new Sale();

            sale2.Quantity  = 2;
            sale2.StoreId   = "7131";
            sale2.OrderNum  = "QA879.1";
            sale2.PayTerms  = "Net 20";
            sale2.OrderDate = DateTime.Now;

            book1.Sales.Add(sale1);
            book2.Sales.Add(sale2);

            publisher.Books.Add(book1);
            publisher.Books.Add(book2);

            _context.Publishers.Add(publisher);
            _context.SaveChanges();

            var publishers = await _context.Publishers
                             .Include(pub => pub.Books)
                             .ThenInclude(book => book.Sales)
                             .Include(pub => pub.Users)
                             .ThenInclude(user => user.Job)
                             .Where(pub => pub.PubId == publisher.PubId)
                             .FirstOrDefaultAsync();

            if (publishers == null)
            {
                return(NotFound());
            }

            return(publishers);
        }
Exemple #3
0
        public async Task <ActionResult <Publisher> > PostPublisherDetails()
        {
            var publisher = new Publisher();

            publisher.PublisherName = "Bonhomie Press";
            publisher.City          = "New York";
            publisher.State         = "NY";
            publisher.Country       = "USA";

            Book book1 = new Book();

            book1.Title         = "This is the new book title";
            book1.PublishedDate = DateTime.UtcNow;

            Book book2 = new Book();

            book2.Title         = "This is the second book title";
            book2.PublishedDate = DateTime.UtcNow;

            Sale sale1 = new Sale();

            sale1.Quantity  = 2;
            sale1.StoreId   = "8042";
            sale1.OrderNum  = "XYZ";
            sale1.PayTerms  = "Net 30";
            sale1.OrderDate = DateTime.Now;

            Sale sale2 = new Sale();

            sale2.Quantity  = 2;
            sale2.StoreId   = "7131";
            sale2.OrderNum  = "QA879.1";
            sale2.PayTerms  = "Net 20";
            sale2.OrderDate = DateTime.Now;

            book1.Sale.Add(sale1);
            book2.Sale.Add(sale2);

            publisher.Book.Add(book1);
            publisher.Book.Add(book2);

            _context.Publisher.Add(publisher);
            _context.SaveChanges();

            var publishers = _context.Publisher
                             .Include(pub => pub.Book)
                             .ThenInclude(book => book.Sale)
                             .Include(pub => pub.User)
                             .ThenInclude(user => user.Role)
                             .Where(pub => pub.PubId == publisher.PubId)
                             .FirstOrDefault();

            if (publisher == null)
            {
                return(NotFound());
            }

            return(publisher);
        }
Exemple #4
0
        public async Task <ActionResult <Publisher> > PostPublisherDetals()
        {
            var publisher_1 = new Publisher();

            publisher_1.PublisherName = "Bhashitha";
            publisher_1.City          = "Elpitiya";
            publisher_1.State         = "G";
            publisher_1.Country       = "Srilanka";

            Book b1 = new Book();

            b1.Title         = "Good night moon 1";
            b1.PublishedDate = DateTime.Now;

            Book b2 = new Book();

            b2.Title         = "Good night moon 2";
            b2.PublishedDate = DateTime.Now;


            Sale sale1 = new Sale();

            sale1.Quantity  = 2;
            sale1.StoreId   = "8042";
            sale1.OrderNum  = "XYZ";
            sale1.PayTerms  = "Net 30";
            sale1.OrderDate = DateTime.Now;

            Sale sale2 = new Sale();

            sale2.Quantity  = 2;
            sale2.StoreId   = "7131";
            sale2.OrderNum  = "QA879.1";
            sale2.PayTerms  = "Net 20";
            sale2.OrderDate = DateTime.Now;

            b1.Sale.Add(sale1);
            b2.Sale.Add(sale2);

            publisher_1.Book.Add(b1);
            publisher_1.Book.Add(b2);

            _context.Publisher.Add(publisher_1);
            _context.SaveChanges();


            var publisher = _context.Publisher
                            .Where(pub => pub.PubId == publisher_1.PubId)
                            .FirstOrDefault();

            if (publisher == null)
            {
                return(NotFound());
            }

            return(publisher);
        }
Exemple #5
0
        public IEnumerable <Publisher> Get()
        {
            //CRUD
            using (var _context = new BookStoresDBContext())
            {
                //Publisher publisher = new Publisher();
                //publisher.PublisherName = "Egmont Book";

                //_context.Publishers.Add(publisher);
                //_context.SaveChanges();

                Publisher publisher = _context.Publishers.FirstOrDefault();
                //publisher.PublisherName = "Egmond Books";
                _context.Publishers.Remove(publisher);
                _context.SaveChanges();

                return(_context.Publishers.ToList());
            }
        }
Exemple #6
0
        public IEnumerable <Publisher> Get()
        {
            using (var _context = new BookStoresDBContext())
            {
                //Publisher publisher = new Publisher();
                //publisher.PublisherName = "Max Payne";
                //_context.Publishers.Add(publisher);
                //_context.SaveChanges();

                //Update first publisher always.........................................
                //Publisher publisher = _context.Publishers.FirstOrDefault();
                //publisher.PublisherName = "Max Payne II";
                //_context.SaveChanges();

                //Remove the first publisher in the list always......................................
                Publisher publisher = _context.Publishers.FirstOrDefault();
                _context.Publishers.Remove(publisher);
                _context.SaveChanges();


                return(_context.Publishers.ToList());
            }
        }
Exemple #7
0
        public IEnumerable <Author> Get()
        {
            using (var context = new BookStoresDBContext())
            {
                // Get All
                // return context.Author.ToList();

                // Add an author

                /*Author author = new Author();
                 *
                 * author.FirstName = "John";
                 * author.LastName = "Smith";
                 * author.Phone = "123-456-7890";
                 * author.State = "FL";
                 * author.Zip = "12345";
                 *
                 * context.Author.Add(author);
                 *
                 * context.SaveChanges();*/

                Author author = context.Author.Where(auth => auth.AuthorId == 25).FirstOrDefault();

                /*               author.Phone = "111-111-1111";
                 *
                 *             context.Author.Update(author);
                 *
                 *             context.SaveChanges();*/
                // Get bi Id
                // return context.Author.Where(auth => auth.AuthorId == 4).ToList();

                context.Author.Remove(author);
                context.SaveChanges();

                return(context.Author.ToList());
            }
        }