Exemple #1
0
 /// <summary>
 /// Returns the current logged-in user.
 /// </summary>
 /// <returns>
 /// Returns the current logged-in user.
 /// </returns>
 /// <param name="name">The input username.</param>
 public user GetUser(string name)
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         return(bookstoreDBcontext.users.Where(a => a.Username == name).FirstOrDefault());
     }
 }
Exemple #2
0
 /// <summary>
 /// Returns book by input barcode.
 /// </summary>
 /// <returns>
 /// Returns book by input barcode.
 /// </returns>
 /// <param name="barcode]">The barcode of the book.</param>
 public book GetBookByBarcode(int barcode)
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         return(bookstoreDBcontext.books.Where(a => a.barcodeId == barcode).FirstOrDefault());
     }
 }
Exemple #3
0
 /// <summary>
 /// Returns a list with all registered users.
 /// </summary>
 /// <returns>
 /// Returns a list with all registered users.
 /// </returns>
 public List <user> GetAllUsers()
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         return(bookstoreDBcontext.users.ToList());
     }
 }
Exemple #4
0
 /// <summary>
 /// Returns the type of the input book.
 /// </summary>
 /// <returns>
 /// Returns the type of the input book.
 /// </returns>
 /// <param name="book]">The input book.</param>
 public booktype GetBookType(book book)
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         return(bookstoreDBcontext.booktypes.Where(a => a.Id == book.BookTypeId).FirstOrDefault());
     }
 }
Exemple #5
0
 /// <summary>
 /// Returns the count of the books.
 /// </summary>
 /// <returns>
 /// Returns the count of the books.
 /// </returns>
 public int GetAllBarcodesCount()
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         return(bookstoreDBcontext.books.ToList().Count());
     }
 }
Exemple #6
0
 /// <summary>
 /// Returns all books from the database.
 /// </summary>
 /// <returns>
 /// Returns all books from the database.
 /// </returns>
 public List <book> GetAllBooks()
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         return(bookstoreDBcontext.books.ToList());
     }
 }
Exemple #7
0
        /// <summary>
        /// Removes a user by input name.
        /// </summary>
        /// <param name="name">The input username.</param>
        public void RemoveUser(string name)
        {
            user user = GetUser(name);

            using (bookstoreDBcontext = new bookshopEntities1())
            {
                bookstoreDBcontext.users.Attach(user);
                bookstoreDBcontext.users.Remove(user);
                bookstoreDBcontext.SaveChanges();
            }
        }
Exemple #8
0
 /// <summary>
 /// Creates new user into the database.
 /// </summary>
 /// <param name="name">The input username.</param>
 /// <param name="password">The input password.</param>
 public void AddUser(string name, string password)
 {
     using (bookstoreDBcontext = new bookshopEntities1())
     {
         user user = new user();
         user.Username = name;
         user.Password = password;
         bookstoreDBcontext.users.Add(user);
         bookstoreDBcontext.SaveChanges();
     }
 }
Exemple #9
0
        /// <summary>
        /// Restocks the amount of the input book.
        /// </summary>
        /// <param name="book]">The book to be restocked.</param>
        /// <param name="quantity]">The amount to be added into the current.</param>
        public void UpdateBookQuantity(book book, int quantity)
        {
            book book1 = book;

            book1.Number = quantity;

            using (bookstoreDBcontext = new bookshopEntities1())
            {
                bookstoreDBcontext.books.AddOrUpdate(book1);
                bookstoreDBcontext.SaveChanges();
            }
        }
Exemple #10
0
        public void AssertThatDatabaseContainsCertainBook()
        {
            List <book> booksFromDB = new List <book>();

            using (dbContext = new bookshopEntities1())
            {
                booksFromDB = this.dbContext.books.ToList();
            }

            bool containsTheBook = booksFromDB.Select(x => x).Where(x => x.barcodeId == 105).Count() > 0;

            Assert.AreEqual(containsTheBook, true, "Business dbContext differs from the original context.");
        }
Exemple #11
0
        public void AssertThatDatabaseContainsCertainUser()
        {
            List <user> usersFromDB = new List <user>();

            using (dbContext = new bookshopEntities1())
            {
                usersFromDB = this.dbContext.users.ToList();
            }

            bool containsTheUser = usersFromDB.Select(x => x).Where(x => x.Username == "user").Count() > 0;

            Assert.AreEqual(containsTheUser, true, "Business dbContext differs from the original context.");
        }
Exemple #12
0
        public void UpdateBookQuantityAfterPurchaseTestOne()
        {
            using (dbContext = new bookshopEntities1())
            {
                book firstBook        = dbContext.books.Where(b => b.barcodeId == 101).First();
                int  originalQuantity = firstBook.Number;
                int  quantity         = 4;

                business.UpdateBook(firstBook, quantity);
                firstBook = dbContext.books.Where(b => b.barcodeId == 101).First();
                Assert.AreEqual(originalQuantity, quantity + firstBook.Number, "Book quantity do not change after purchase.");
            }
        }
Exemple #13
0
        /// <summary>
        /// Gets old user with his password and checks if it exists and replaces it.
        /// </summary>
        /// <param name="user">Contains user information.</param>
        public void UpdateUserPass(user user)
        {
            using (bookstoreDBcontext = new bookshopEntities1())
            {
                var pass = bookstoreDBcontext.users.Where(a => a.Username == user.Username).FirstOrDefault();

                if (pass != null)
                {
                    user.Id = pass.Id;
                    bookstoreDBcontext.Entry(pass).CurrentValues.SetValues(user);
                    bookstoreDBcontext.SaveChanges();
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// Adds a book by input name, author, publisher, quantity, costPrice,
        /// sellingPrice and identifier for the book type.
        /// </summary>
        /// <param name="name">The name of the book.</param>
        /// <param name="author">The author of the book.</param>
        /// <param name="publisher">The publisher of the book.</param>
        /// <param name="quantity">The quantity of the book.</param>
        /// <param name="costPrice">The cost of the book.</param>
        /// <param name="sellingPrice">The sell price of the book.</param>
        /// <param name="bookTypeId">The identifier's type of the book.</param>
        public void AddBook(string name, string author, string publisher, int quantity, float costPrice, double sellingPrice, int bookTypeId)
        {
            using (bookstoreDBcontext = new bookshopEntities1())
            {
                book book = new book();
                book.Author     = author;
                book.Number     = quantity;
                book.Price      = costPrice;
                book.Publisher  = publisher;
                book.Book1      = name;
                sellingPrice    = costPrice + 7; // + 7leva
                book.BookTypeId = bookTypeId;

                bookstoreDBcontext.books.Add(book);
                bookstoreDBcontext.SaveChanges();
            }
        }
Exemple #15
0
        public void UpdateUserPasswordTest()
        {
            business.AddUser("Ivan Ivanov", "httrersgsa");
            string userPassword = null;
            string newPassword  = "******";

            using (dbContext = new bookshopEntities1())
            {
                user ivan = dbContext.users.Where(u => u.Username == "Ivan Ivanov").First();
                ivan.Password = newPassword;
                business.UpdateUserPass(ivan);
                userPassword = dbContext.users.Where(u => u.Username == "Ivan Ivanov").First().Password;
            }

            business.RemoveUser("Ivan Ivanov");
            Assert.AreEqual(userPassword, newPassword, "The user password do not change.");
        }