Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
     }
 }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
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();
            }
        }