Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Bookshop ctx = new Bookshop();
         useremail = Session["eadd"].ToString();
         if (useremail == null)
         {
             Response.Redirect("~/Login.aspx");
         }
         if (ctx.Users.ToList().Find(x => x.EmailAddress == useremail) != null)
         {
             userid = ctx.Users.ToList().Find(x => x.EmailAddress == useremail).UserID;
             CheckExistingCredit(userid);
             DDL_Month_Year_Bind();
             myCart = (Cart)Session["cart"];
             BindGrid();
         }
         else
         {
             Response.Redirect("~/Login.aspx");
             //Session["lastPage"] = this.Page.Title;
         }
     }
 }
Example #2
0
 public static List <Book> AllBooks()
 {
     using (Bookshop entities = new Bookshop())
     {
         return(entities.Books.ToList <Book>());
     }
 }
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            Bookshop ctx = new Bookshop();

            bool isFound = false;
            int  count   = ctx.Users.Count();

            User[] users = new User[count];
            users = ctx.Users.ToArray();
            for (int i = 0; i < count; i++)
            {
                if (tbx_Email.Text == users[i].EmailAddress)
                {
                    isFound = true;
                }
            }
            if (isFound == false)
            {
                NotifyUserError("User not found, please try again", "Error");
                tbx_Email.Text = "";
            }
            else
            {
                // send an email contain password to the user
                NotifyUser("A temporary password has been sent to you, please check your email", "Successful");
                tbx_Email.Text = "";
            }
        }
Example #4
0
        protected void btn_Change_Click(object sender, EventArgs e)
        {
            Bookshop ctx          = new Bookshop();
            string   emailAddress = (string)Session["eadd"];
            User     u            = ctx.Users.Where(x => x.EmailAddress == emailAddress).First();

            if (u.Passcode == tbx_Password.Text)
            {
                if (tbx_Password.Text == tbx_NewPassword.Text)
                {
                    NotifyUserError("New password cannot be the same as old password", "Error");
                    tbx_Password.Text        = "";
                    tbx_NewPassword.Text     = "";
                    tbx_ConfirmPassword.Text = "";
                }
                else
                {
                    NotifyUser("Password successfully changed", "Successful");
                    u.Passcode = tbx_NewPassword.Text;
                    ctx.SaveChanges();
                    Session["passwordChanged"] = "true";
                    Response.Redirect("Profile.aspx");
                }
            }
            else
            {
                NotifyUserError("Original password not correct, please try again", "Error");
                tbx_Password.Text        = "";
                tbx_NewPassword.Text     = "";
                tbx_ConfirmPassword.Text = "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Bookshop ctx          = new Bookshop();
            string   emailAddress = (string)Session["eadd"];

            if (emailAddress == "")
            {
                Response.Redirect("Home.aspx");
            }

            if (!IsPostBack)
            {
                emailAddress = (string)Session["eadd"];
                User u = ctx.Users.Where(x => x.EmailAddress == emailAddress).First();
                tbx_Title.Text           = u.Title;
                tbx_FirstName.Text       = u.FirstName;
                tbx_LastName.Text        = u.LastName;
                lbl_EmailAddress.Text    = u.EmailAddress;
                tbx_ShippingAddress.Text = u.ShippingAddress;
                tbx_UserName.Text        = u.UserName;

                if ((string)Session["profileChanged"] == "true")
                {
                    NotifyUser("Your profile is updated", "Successful");
                }
                if ((string)Session["passwordChanged"] == "true")
                {
                    NotifyUser("Password successfully changed", "Successful");
                }
            }
        }
Example #6
0
 public static List <Category> ByCategory()
 {
     using (Bookshop entities = new Bookshop())
     {
         return(entities.Categories.ToList <Category>());
     }
 }
Example #7
0
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "select")
        {
            Label  isbn = (e.Item.FindControl("ISBN") as Label);
            string ISBN = isbn.Text;

            using (Bookshop bs = new Bookshop())
            {
                Book bk = bs.Books.Where(x => x.ISBN == ISBN).ToList()[0];
                Session["ID"]             = bk.BookID;
                Session["Title"]          = bk.Title;
                Session["ISBN"]           = bk.ISBN;
                Session["Author"]         = bk.Author;
                Session["CategoryID"]     = bk.CategoryID;
                Session["Price"]          = bk.Price;
                Session["DiscountFactor"] = bk.DiscFact;


                var query = from x in bs.Books where x.ISBN == ISBN select new { x.Category.Name };
                Session["CategoryName"] = query.First().Name.ToString();
            }
            Response.Redirect("BookDetails.aspx");
        }
    }
Example #8
0
 public static List <Promotion> GetPromotionbyScope(string scope)
 {
     using (Bookshop entities = new Bookshop())
     {
         return(entities.Promotions.Where(x => x.Scope == scope).ToList <Promotion>());
     }
 }
Example #9
0
        public static Book GetBook(int id)
        {
            using (Bookshop entities = new Bookshop())
            {
                Book book = entities.Books.Where(b => b.BookID == id).FirstOrDefault <Book>();

                return(book);
            }
        }
Example #10
0
 public static void deletebook(int bookid)
 {
     using (Bookshop entities = new Bookshop())
     {
         Book book = entities.Books.Where(p => p.BookID == bookid).First <Book>();
         entities.Books.Remove(book);
         entities.SaveChanges();
     }
 }
Example #11
0
        public void TwoSameBooks_CalculatesCorrect()
        {
            var dict = new Dictionary <string, int>();

            dict.Add("1", 2);

            var result = Bookshop.Calculate(new Basket(dict));

            Assert.AreEqual(16.0m, result);
        }
Example #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Bookshop ctx          = new Bookshop();
            string   emailAddress = (string)Session["eadd"];

            if (emailAddress == "")
            {
                Response.Redirect("Home.aspx");
            }
        }
Example #13
0
        public void Checkout_WhenSinglePotterBookIsPurchased_ReturnsPriceOf8(string bookNumber)
        {
            var bookshop = new Bookshop();

            bookshop.AddToBasket(bookNumber);
            var checkoutTotal = bookshop.CheckoutBasket();

            var expected = 8M;

            Assert.Equal(expected, checkoutTotal.DiscountedPriceTotal);
        }
Example #14
0
        public void TwoDifferentBooks_CalculatesCorrectDiscount()
        {
            var dict = new Dictionary <string, int>();

            dict.Add("1", 1);
            dict.Add("2", 1);

            var result = Bookshop.Calculate(new Basket(dict));

            Assert.AreEqual(15.2m, result);
        }
Example #15
0
        public void Checkout_WhenNoBooksArePurchased_ReturnsPriceOf0()
        {
            var bookshop = new Bookshop();

            bookshop.AddToBasket("");
            var checkoutTotal = bookshop.CheckoutBasket();

            var expected = 0;

            Assert.Equal(expected, checkoutTotal.DiscountedPriceTotal);
        }
Example #16
0
        public void ComplexScenario1_CalculatesCorrectDiscount()
        {
            var dict = new Dictionary <string, int>();

            dict.Add("2", 2);
            dict.Add("1", 2);
            dict.Add("3", 1);

            var result = Bookshop.Calculate(new Basket(dict));

            Assert.AreEqual(36.8m, result);
        }
Example #17
0
        public void Checkout_WhenTwoOfTheSameBooksArePurchased_ReturnsPriceOf16()
        {
            var bookshop = new Bookshop();

            bookshop.AddToBasket("first");
            bookshop.AddToBasket("first");
            var checkoutTotal = bookshop.CheckoutBasket();

            var expected = 16M;

            Assert.Equal(expected, checkoutTotal.DiscountedPriceTotal);
        }
Example #18
0
        protected void btn_Login_Click(object sender, EventArgs e)
        {
            Bookshop ctx = new Bookshop();

            bool isFound = false;
            int  count   = ctx.Users.Count();

            User[] users = new User[count];
            users = ctx.Users.ToArray();
            for (int i = 0; i < count; i++)
            {
                if (tbx_EmailAdress.Text == users[i].EmailAddress)
                {
                    isFound = true;
                }
            }
            if (isFound == false)
            {
                tbx_EmailAdress.Text = "";
                tbx_Password.Text    = "";
                NotifyUserError("Wrong email address or password, please try again", "Error");
            }
            else
            {
                User u = ctx.Users.Where(x => x.EmailAddress == tbx_EmailAdress.Text).First();
                Session["eadd"] = u.EmailAddress;
                if (u.Passcode != tbx_Password.Text)
                {
                    tbx_EmailAdress.Text = "";
                    tbx_Password.Text    = "";
                    NotifyUserError("Wrong email address or password, please try again", "Error");
                }
                else
                {
                    if (u.Passcode == tbx_Password.Text && u.UserType == "Owner")
                    {
                        Response.Redirect("Dashboard.aspx");
                    }
                    else if (u.Passcode == tbx_Password.Text && u.UserType == "RUser")
                    {
                        if ((string)Session["lastPage"] != "")
                        {
                            Response.Redirect((string)Session["lastPage"]);
                        }
                        else
                        {
                            Response.Redirect("Home.aspx");
                        }
                    }
                }
            }
        }
Example #19
0
        public void Checkout_WhenOnlyDifferentBooksArePurchased_ReturnsCorrectDiscountedPrice(string[] purchasedBooks, decimal expected)
        {
            var bookshop = new Bookshop();

            foreach (string book in purchasedBooks)
            {
                bookshop.AddToBasket(book);
            }
            ;
            var checkoutTotal = bookshop.CheckoutBasket();

            Assert.Equal(expected, checkoutTotal.DiscountedPriceTotal);
        }
Example #20
0
 public static void updatebooks(int bookid, string title, int catid, string isbn, string author, int stock, decimal price)
 {
     using (Bookshop entities = new Bookshop())
     {
         Book book = entities.Books.Where(p => p.BookID == bookid).First <Book>();
         book.Title      = title;
         book.ISBN       = isbn;
         book.CategoryID = catid;
         book.Author     = author;
         book.Stock      = stock;
         book.Price      = price;
         entities.SaveChanges();
     }
 }
Example #21
0
        public void Checkout_WhenMultipleDiscountsArePossible_ReturnsLowestDiscountedPrices(string[] purchasedBooks, decimal expected)
        {
            var bookshop = new Bookshop();

            foreach (string book in purchasedBooks)
            {
                bookshop.AddToBasket(book);
            }
            ;

            var checkoutTotal = bookshop.CheckoutBasket();

            Assert.Equal(expected, checkoutTotal.DiscountedPriceTotal);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            myCart = (Cart)Session["cart"];
            string   isbn = Request.QueryString["isbn"];
            Bookshop ctx  = new Bookshop();

            if (isbn == null)
            {
                b = ctx.Books.ToList().First();
            }
            else
            {
                b = ctx.Books.Where(x => x.ISBN == isbn).First();
            }

            if (!IsPostBack)
            {
                //Book image
                imgBook.ImageUrl = "~/images/" + b.ISBN + ".jpg";
                //Book title
                lblBname.Text = b.Title;
                //Book author
                lblBauthor.Text = b.Author;
                //Book original price
                lblOprice.Text = "S$" + b.Price.ToString();
                //Book stock
                if (b.Stock > 0)
                {
                    lblStock.Text = b.Stock.ToString() + " copies available";
                }
                else
                {
                    lblStock.Text      = "Not Available Now";
                    btnAddCart.Visible = false;
                }
                //Book ISBN
                lblIsbn.Text = b.ISBN;


                //Book Category
                int      cid = b.CategoryID;
                Category c   = ctx.Categories.Where(x => x.CategoryID == cid).First();
                lblCategory.Text = c.Name;

                //Sam's method
                bkColl = GetRelatedColl();
                DisplayRelatedColl();
            }
        }
        protected void btn_Update_Click(object sender, EventArgs e)
        {
            Bookshop ctx = new Bookshop();
            User     u   = ctx.Users.Where(x => x.EmailAddress == lbl_EmailAddress.Text).First();

            u.Title           = tbx_Title.Text;
            u.FirstName       = tbx_FirstName.Text;
            u.LastName        = tbx_LastName.Text;
            u.ShippingAddress = tbx_ShippingAddress.Text;
            u.UserName        = tbx_UserName.Text;

            ctx.SaveChanges();
            Session["profileChanged"] = "true";
            Response.Redirect("Profile.aspx");
        }
 private void AddShippinginfo(string email)
 {
     using (Bookshop entities = new Bookshop())
     {
         if (usr.ShippingAddress == "")
         {
             usr.ShippingAddress = "123 ISS NUS, Singapore 123456";
             usr.LastName        = "user";
             usr.FirstName       = "user";
             usr.Title           = "Mr";
         }
         lblshippingaddress.Text = usr.ShippingAddress;
         lblcustname.Text        = usr.Title + "." + usr.FirstName + usr.LastName;
         lblemail.Text           = usr.EmailAddress;
     }
 }
Example #25
0
        protected void btn_Create_Click(object sender, EventArgs e)
        {
            Bookshop ctx = new Bookshop();

            if (tbx_Email.Text != "")
            {
                bool   isFound = false;
                int    count   = ctx.Users.Count();
                User[] users   = new User[count];
                users = ctx.Users.ToArray();
                for (int i = 0; i < count; i++)
                {
                    if (tbx_Email.Text == users[i].EmailAddress)
                    {
                        isFound = true;
                    }
                }
                if (isFound == true)
                {
                    NotifyUserError("Duplicate email address, please enter another one", "Error");
                    tbx_Email.Text = "";
                    isFound        = false;
                }
                else
                {
                    NotifyUser("Account successfully created, please log in", "Successful");
                    User u = new User();
                    u.UserName        = tbx_Username.Text;
                    u.UserType        = "RUser";
                    u.EmailAddress    = tbx_Email.Text;
                    u.Passcode        = tbx_Password.Text;
                    u.DateJoined      = DateTime.Today;
                    u.Title           = "";
                    u.LastName        = "";
                    u.FirstName       = "";
                    u.ShippingAddress = "";
                    ctx.Users.Add(u);
                    ctx.SaveChanges();
                    tbx_Email.Text    = "";
                    tbx_Username.Text = "";
                }
            }
            else
            {
                NotifyUserError("Please fill email address", "Error");
            }
        }
Example #26
0
 public static void AddNewBook(string title, int catid, string isbn, string author, int stock, decimal price)
 {
     using (Bookshop entities = new Bookshop())
     {
         Book book = new Book()
         {
             Title      = title,
             CategoryID = catid,
             ISBN       = isbn,
             Author     = author,
             Stock      = stock,
             Price      = price,
         };
         entities.Books.Add(book);
         entities.SaveChanges();
     }
 }
Example #27
0
 public static void adddiscount(string scope, string promoitem, DateTime startdate, DateTime enddate, int discountamt)
 {
     using (Bookshop entities = new Bookshop())
     {
         Promotion promo = new Promotion
         {
             PromoID     = entities.Promotions.Count() > 0 ? entities.Promotions.Max(c => c.PromoID) + 1 : 1,
             Scope       = scope,
             PromoItem   = promoitem,
             StartDate   = startdate,
             EndDate     = enddate,
             DiscountAmt = discountamt,
         };
         entities.Promotions.Add(promo);
         entities.SaveChanges();
     }
 }
Example #28
0
        public static IQueryable <BookList> GetBooklists(string searchquery)
        {
            var entities = new Bookshop();

            var categoryname = entities.Categories.Where(x => x.Name.Contains(searchquery)).SingleOrDefault();

            // IQueryable<BookList> booklist = entities.Books.Where(b => b.Author == author || b.Title == title || b.CategoryID == category);
            if (categoryname != null)
            {
                IQueryable <BookList> booklist = from a in entities.Books.Where(a => a.Author.Contains(searchquery) || a.Title.Contains(searchquery) || a.ISBN.Contains(searchquery) || a.CategoryID == categoryname.CategoryID)
                                                 from b in entities.Categories
                                                 where a.CategoryID == b.CategoryID
                                                 select new BookList
                {
                    BookID       = a.BookID,
                    Author       = a.Author,
                    CategoryID   = a.CategoryID,
                    CategoryName = b.Name,
                    Title        = a.Title,
                    ISBN         = a.ISBN,
                    Price        = a.Price,
                    Stock        = a.Stock
                };
                return(booklist);
            }
            else
            {
                IQueryable <BookList> booklist = from a in entities.Books.Where(a => a.Author.Contains(searchquery) || a.Title.Contains(searchquery) || a.ISBN.Contains(searchquery))
                                                 from b in entities.Categories
                                                 where a.CategoryID == b.CategoryID
                                                 select new BookList
                {
                    BookID       = a.BookID,
                    Author       = a.Author,
                    CategoryID   = a.CategoryID,
                    CategoryName = b.Name,
                    Title        = a.Title,
                    ISBN         = a.ISBN,
                    Price        = a.Price,
                    Stock        = a.Stock
                };
                return(booklist);
            }
        }
Example #29
0
        public void Checkout_WhenTwoOfEveryBooksIsPurchased_ReturnsDiscountedPrice()
        {
            var bookshop = new Bookshop();

            bookshop.AddToBasket("first");
            bookshop.AddToBasket("second");
            bookshop.AddToBasket("third");
            bookshop.AddToBasket("fourth");
            bookshop.AddToBasket("fifth");
            bookshop.AddToBasket("first");
            bookshop.AddToBasket("second");
            bookshop.AddToBasket("third");
            bookshop.AddToBasket("fourth");
            bookshop.AddToBasket("fifth");
            var checkoutTotal = bookshop.CheckoutBasket();

            var expected = 60M;

            Assert.Equal(expected, checkoutTotal.DiscountedPriceTotal);
        }
Example #30
0
        public static IQueryable <BookList> GetBooklistAll()
        {
            var entities = new Bookshop();
            //IQueryable<Book> booklist = entities.Books;
            IQueryable <BookList> booklist = from a in entities.Books
                                             from b in entities.Categories
                                             where a.CategoryID == b.CategoryID
                                             select new BookList
            {
                BookID       = a.BookID,
                Author       = a.Author,
                CategoryID   = a.CategoryID,
                CategoryName = b.Name,
                Title        = a.Title,
                ISBN         = a.ISBN,
                Price        = a.Price,
                Stock        = a.Stock
            };

            return(booklist);
        }