Ejemplo n.º 1
0
 public IEnumerable <Book> GetBookByUserID(int userID)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         return(_context.Books.Include("Genre").Include("Language").Where(m => m.UserID == userID).ToList());
     }
 }
Ejemplo n.º 2
0
        public IEnumerable <Book> GetOrderedBookBySellerID(int userID)
        {
            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                IList <Book> sellerBooks = _context.Books.Where(m => m.UserID == userID).ToList();

                IList <Book> orderedSellerBooks = new List <Book>();

                foreach (Book book in sellerBooks)
                {
                    IList <CartBook> cartBooks = _context.CartBooks.Where(m => m.BookID == book.BookID).ToList();

                    foreach (CartBook cartBook in cartBooks)
                    {
                        IList <Order> orders = _context.Orders.Where(m => m.CartID == cartBook.CartID).ToList();

                        foreach (Order order in orders)
                        {
                            if (order.CartID == cartBook.CartID)
                            {
                                Book orderedBook = _context.Books.Include("Genre").Include("Language").Where(m => m.BookID == cartBook.BookID).SingleOrDefault();

                                orderedSellerBooks.Add(orderedBook);
                            }
                        }
                    }
                }
                if (orderedSellerBooks == null)
                {
                    return(null);
                }
                return(orderedSellerBooks);
            }
        }
Ejemplo n.º 3
0
 public string Add(Book book)
 {
     using (BookShoppeDBContext booksContext = new BookShoppeDBContext())
     {
         // Transaction Meathod Testing
         using (DbContextTransaction dbTran = booksContext.Database.BeginTransaction())
         {
             try
             {
                 if (book.UserID == 0)
                 {
                     return("User ID needed");
                 }
                 booksContext.Books.Add(book);
                 booksContext.SaveChanges();
                 dbTran.Commit();
             }
             catch (Exception)
             {
                 dbTran.Rollback();
                 return(null);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
 public IEnumerable <Book> GetBooksByLanguage(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         return(_context.Books.Include("Genre").Include("Language").Where(b => b.LanguageID == id).ToList());
     }
 }
Ejemplo n.º 5
0
 public IEnumerable <Book> GetAllBooks()
 {
     using (BookShoppeDBContext booksContext = new BookShoppeDBContext())
     {
         return(booksContext.Books.Include("Genre").Include("Language").ToList());
     }
 }
Ejemplo n.º 6
0
 public IEnumerable <Language> GetAllLanguages()
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         return(_context.Languages.ToList());
     }
 }
Ejemplo n.º 7
0
        public IEnumerable <Book> GetUserCartDetails(int id)
        {
            List <Book> books = new List <Book>();

            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                try
                {
                    Cart cart = new Cart();
                    cart = GetCartNotInOrder(id);
                    if (cart != null)
                    {
                        int cartID = cart.CartID;

                        List <CartBook> cartBooks = _context.CartBooks.Where(cb => cb.CartID == cartID).ToList();

                        foreach (var item in cartBooks)
                        {
                            Book book = _context.Books.Where(ID => ID.BookID == item.BookID).SingleOrDefault();
                            books.Add(book);
                        }
                        return(books);
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 8
0
 public Book GetBookDetails(int bookID)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         return(_context.Books.Include("Genre").Where(ID => ID.BookID == bookID).SingleOrDefault());
     }
 }
Ejemplo n.º 9
0
 public IEnumerable <Genre> GetAllGenres()
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         return(_context.Genres.ToList());
     }
 }
Ejemplo n.º 10
0
 public Book GetBookByID(int bookID)
 {
     using (BookShoppeDBContext booksContext = new BookShoppeDBContext())
     {
         Book book = booksContext.Books.Include("Genre").Include("Language").SingleOrDefault(ID => ID.BookID == bookID);
         return(book);
     }
 }
Ejemplo n.º 11
0
        public User ValidateLogIn(string userName, string password)
        {
            User _user = null;
            BookShoppeDBContext _Context = new BookShoppeDBContext();

            _user = _Context.Users.Include("Role").Where(u => u.UserName == userName && u.Password == password).SingleOrDefault();
            return(_user);
        }
Ejemplo n.º 12
0
 public string GetLanguageByLanguageID(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         Language language = _context.Languages.Where(l => l.LanguageID == id).SingleOrDefault();
         return(language.LanguageName);
     }
 }
Ejemplo n.º 13
0
 public string GetGenreByGenreID(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         Genre genre = _context.Genres.Where(ID => ID.GenreID == id).SingleOrDefault();
         return(genre.GenreName);
     }
 }
Ejemplo n.º 14
0
 public void Delete(int BookID)
 {
     using (BookShoppeDBContext bookContext = new BookShoppeDBContext())
     {
         Book book = bookContext.Books.Where(id => id.BookID == BookID).FirstOrDefault();
         bookContext.Books.Remove(book);
         bookContext.SaveChanges();
     }
 }
Ejemplo n.º 15
0
 public void RemoveBookFormUserCart(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         CartBook cartBooks = _context.CartBooks.Where(cb => cb.BookID == id).SingleOrDefault();
         _context.CartBooks.Remove(cartBooks);
         _context.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public string Edit(Book book)
 {
     using (BookShoppeDBContext booksContext = new BookShoppeDBContext())
     {
         booksContext.Entry(book).State = EntityState.Modified;
         booksContext.SaveChanges();
         return(null);
     }
 }
Ejemplo n.º 17
0
 public void RemoveBookFormWishlist(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         WishList wishlist = _context.WishList.Where(w => w.BookID == id).SingleOrDefault();
         _context.WishList.Remove(wishlist);
         _context.SaveChanges();
     }
 }
Ejemplo n.º 18
0
 public bool Delete(int id)
 {
     using (var Context = new BookShoppeDBContext())
     {
         User user = Context.Users.Where(ID => ID.UserID == id).FirstOrDefault();
         Context.Users.Remove(user);
         Context.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 19
0
 public string DeleteGenre(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         Genre genre = _context.Genres.Where(Id => Id.GenreID == id).FirstOrDefault();
         _context.Genres.Remove(genre);
         _context.SaveChanges();
         return("Genre Removed Successfully");
     }
 }
Ejemplo n.º 20
0
 public string DeleteLanguage(int id)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         Language language = _context.Languages.Where(l => l.LanguageID == id).SingleOrDefault();
         _context.Languages.Remove(language);
         _context.SaveChanges();
         return("Language Removed Successfully");
     }
 }
Ejemplo n.º 21
0
        public string AddUser(User user)
        {
            BookShoppeDBContext _Context = new BookShoppeDBContext();

            _Context.Users.Add(user);

            _Context.SaveChanges();

            return(null);
        }
Ejemplo n.º 22
0
 public bool CheckBookInWishList(int userID, int bookID)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         WishList wishlist = _context.WishList.Where(ID => ID.UserID == userID && ID.BookID == bookID).SingleOrDefault();
         if (wishlist == null)
         {
             return(false);
         }
         return(true);
     }
 }
Ejemplo n.º 23
0
        public bool CheckCartInOrders(int id)
        {
            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                Cart  cart  = _context.Carts.Where(c => c.UserID == id).SingleOrDefault();
                Order order = _context.Orders.Where(o => o.CartID == cart.CartID).Single();

                if (order == null)
                {
                    return(false); // Return false when the Cart is not in the orders
                }
                return(true);      // Return true when the cart is available in the orders
            }
        }
Ejemplo n.º 24
0
 public string AddToWishList(int userID, int bookID)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         WishList wishlist = new WishList()
         {
             UserID = userID,
             BookID = bookID
         };
         _context.WishList.Add(wishlist);
         _context.SaveChanges();
         return(null);
     }
 }
Ejemplo n.º 25
0
        public int GetCartRate(int cartID)
        {
            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                int             cartRate  = 0;
                List <CartBook> cartBooks = _context.CartBooks.Where(cb => cb.CartID == cartID).ToList();

                foreach (var item in cartBooks)
                {
                    Book book = _context.Books.Where(ID => ID.BookID == item.BookID).SingleOrDefault();
                    cartRate = cartRate + book.Price;
                }
                return(cartRate);
            }
        }
Ejemplo n.º 26
0
        public IEnumerable <Book> GetUserWishlist(int id)
        {
            List <Book> books = new List <Book>();

            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                List <WishList> wishlist = _context.WishList.Where(ID => ID.UserID == id).ToList();

                foreach (var item in wishlist)
                {
                    Book book = _context.Books.Where(ID => ID.BookID == item.BookID).SingleOrDefault();
                    books.Add(book);
                }
                return(books);
            }
        }
Ejemplo n.º 27
0
 public string AddGenre(Genre genre)
 {
     using (BookShoppeDBContext _context = new BookShoppeDBContext())
     {
         _context.Genres.Add(genre);
         try
         {
             _context.SaveChanges();
         }
         catch (DbUpdateException e)
         {
             return(e.Message);
         }
         return(null);
     }
 }
Ejemplo n.º 28
0
        // Not Used In Function
        private Cart CheckCartInOrder(int cartID)
        {
            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                Cart cart = _context.Carts.Where(c => c.UserID == cartID).SingleOrDefault();

                Order order = _context.Orders.Where(o => o.CartID == cartID).SingleOrDefault();

                if (order == null)
                {
                    return(cart);
                }

                return(null);
            }
        }
Ejemplo n.º 29
0
        public bool PlaceOrder(Shipment shipment)
        {
            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                Order order = new Order();
                order.ShipmentID = shipment.ShipmentID;
                Cart cart = _context.Carts.Where(c => c.UserID == shipment.UserID && c.IsOrdered == false).SingleOrDefault();
                order.CartID = cart.CartID;

                _context.Orders.Add(order);
                cart.IsOrdered = true;

                _context.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 30
0
        public string AddLanguage(Language language)
        {
            using (BookShoppeDBContext _context = new BookShoppeDBContext())
            {
                _context.Languages.Add(language);
                try
                {
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    return(e.Message);
                }

                return(null);
            }
        }