예제 #1
0
 public static List <Book> Listbook()
 {
     using (Mybooks entities = new Mybooks())
     {
         return(entities.Books.ToList <Book>());
     }
 }
예제 #2
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (Mybooks mb = new Mybooks())
                {
                    int    userid   = Convert.ToInt32(txtUserID.Text);
                    string password = Password.Value;
                    if (mb.Users.Where(x => x.UserID == userid)
                        .Where(x => x.Password == password).Count() > 0)
                    {
                        Session["role"]   = "user";
                        Session["userid"] = userid;
                        Response.Redirect("~/RegisteredUsers/Default1.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/UserLogin.aspx");
                    }
                }
            }

            catch (System.FormatException)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Please enter valid credentials');", true);
            }
        }
예제 #3
0
 public static void DeleteBooks(int BookId)
 {
     using (Mybooks entities = new Mybooks())
     {
         Book book = entities.Books.Where(p => p.BookID == BookId).First <Book>();
         entities.Books.Remove(book);
         entities.SaveChanges();
     }
 }
예제 #4
0
        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int BookId = (int)GridView2.SelectedDataKey.Value;

            using (Mybooks entities = new Mybooks())
            {
                Book book = entities.Books.Where(p => p.BookID == BookId).First <Book>();
                DetailsView1.DataSource = new Book[] { book };
                DetailsView1.DataBind();
            }
        }
예제 #5
0
        protected void BtnClick(object sender, EventArgs e)
        {
            mb = new Mybooks();
            Button b   = (Button)sender;
            int    bid = Convert.ToInt32(b.ID);

            CartBook toDel = mb.CartBooks.Where(x =>
                                                (x.UserID == userid) && (x.BookID == bid)).First();

            mb.CartBooks.Remove(toDel);

            mb.SaveChanges();
            Response.Redirect("~/RegisteredUsers/ViewCart.aspx/");
        }
예제 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && Request.QueryString["id"] != null)
            {
                using (Mybooks mb = new Mybooks())
                {
                    int bookid = Convert.ToInt32(Request.QueryString["id"]);
                    if (mb.Books.Where(x => x.BookID == bookid).Count() < 1)
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                    Book   b    = new Work().GetBook(bookid);
                    string isbn = b.ISBN;
                    Image1.ImageUrl = "images/" + isbn + ".jpg";
                    Image1.Style.Add("position", "relative");
                    Image1.Style.Add("float", "right");
                    Image1.Style.Add("margin-right", "40px");
                    Image1.Style.Add("margin-top", "50px");

                    lbltitle.Text = b.Title;
                    lblcate.Text  = mb.Categories
                                    .Where(x => x.CategoryID == b.CategoryID)
                                    .Select(x => x.Name).First();
                    lblisbn.Text   = isbn;
                    lblprice.Text  = String.Format("{0:c}", b.Price);
                    lblauthor.Text = b.Author;

                    if (mb.CartBooks.Where(x => (x.UserID == 1) &&
                                           (x.BookID == b.BookID)).Count() > 0)
                    {
                        btnAdd.Text    = "Already in cart!";
                        btnAdd.Enabled = false;
                    }
                    else if (new Work().CheckStock(b.BookID) < 1)
                    {
                        btnAdd.Text     = "Out of Stock";
                        btnAdd.CssClass = "btn btn-danger";
                        btnAdd.Enabled  = false;
                    }
                    else
                    {
                        btnAdd.PostBackUrl = "~/ViewCart.aspx?id=" + b.BookID;
                    }
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
예제 #7
0
        public static void AddBook(string Title, string ISBN, string Author, int Cat, int Stock, decimal Price)

        {
            Mybooks entities = new Mybooks();
            Book    bk       = new Book();

            bk.Title      = Title;
            bk.Author     = Author;
            bk.ISBN       = ISBN;
            bk.Price      = Price;
            bk.Stock      = Stock;
            bk.CategoryID = Cat;

            entities.Books.Add(bk);
            entities.SaveChanges();
        }
예제 #8
0
        public static void UpdateBooks(int BookId,
                                       string Title, int CategoryID, string Author, string ISBN, int Stock, decimal Price)
        {
            using (Mybooks entities = new Mybooks())
            {
                Book book = entities.Books.Where(p => p.BookID == BookId).First <Book>();
                book.Title      = Title;
                book.CategoryID = CategoryID;
                book.Author     = Author;
                book.ISBN       = ISBN;
                book.Stock      = Stock;
                book.Price      = Price;


                entities.SaveChanges();
            }
        }
예제 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (Mybooks mb = new Mybooks())
                {
                    List <Book> booklist = mb.Books.ToList();
                    foreach (Book bookdetail in booklist)
                    {
                        HtmlGenericControl newDiv  = new HtmlGenericControl("DIV");
                        HtmlGenericControl details = new HtmlGenericControl("DIV");
                        HtmlInputImage     image   = new HtmlInputImage();
                        HtmlAnchor         anch    = new HtmlAnchor();

                        image.Src      = "images/" + bookdetail.ISBN + ".jpg";
                        image.Disabled = true;
                        image.Style.Add("width", "200px");
                        image.Style.Add("height", "220px");

                        anch.InnerHtml = "<hr><strong style=\"font-size: 16px;\">"
                                         + bookdetail.Title + "</strong><br />";

                        details.InnerHtml += bookdetail.Author + "<br />";
                        details.InnerHtml += bookdetail.ISBN + "<br />";
                        details.InnerHtml += "$ " + bookdetail.Price;

                        newDiv.Attributes.Add("class", "col-xs-12 col-sm-6 col-md-4 well");
                        newDiv.Style.Add("height", "500px");
                        newDiv.Style.Add("text-align", "center");
                        newDiv.Style.Add("padding", "30px");

                        anch.HRef = "~/BookDetails1.aspx?id=" + bookdetail.BookID;

                        mainDiv.Controls.Add(newDiv);
                        newDiv.Controls.Add(image);
                        newDiv.Controls.Add(anch);
                        newDiv.Controls.Add(details);
                    }
                }
            }
            else
            {
            }
        }
예제 #10
0
 protected void LoginButton_Click(object sender, EventArgs e)
 {
     using (Mybooks mb = new Mybooks())
     {
         int    userid   = Convert.ToInt32(txtUserID.Text);
         string password = Password.Value;
         if (mb.Users.Where(x => x.UserID == userid)
             .Where(x => x.Password == password)
             .Where(x => x.UserType == "user").Count() > 0)
         {
             Session["role"]   = "user";
             Session["userid"] = userid;
             Response.Redirect("~/RegisteredUsers/BookDetails.aspx");
         }
         else
         {
             Response.Redirect("~/UserLogin.aspx");
         }
     }
 }
예제 #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Mybooks mb;

            if (!IsPostBack && Request.QueryString["id"] != null)
            {
                using (mb = new Mybooks())
                {
                    int bookid = Convert.ToInt32(Request.QueryString["id"]);
                    if (mb.Books.Where(x => x.BookID == bookid).Count() < 1)
                    {
                        Response.Redirect("~/RegisteredUsers/Default1.aspx");
                    }
                    Book   b    = new Work().GetBook(bookid);
                    string isbn = b.ISBN;
                    Image1.ImageUrl = "images/" + isbn + ".jpg";
                    Image1.Style.Add("position", "relative");
                    Image1.Style.Add("float", "right");
                    Image1.Style.Add("margin-right", "40px");
                    Image1.Style.Add("margin-top", "50px");

                    lbltitle.Text = b.Title;
                    lblcate.Text  = mb.Categories
                                    .Where(x => x.CategoryID == b.CategoryID)
                                    .Select(x => x.Name).First();
                    lblisbn.Text   = isbn;
                    lblprice.Text  = String.Format("{0:c}", b.Price);
                    lblauthor.Text = b.Author;

                    btnAdd.Text        = "Log In";
                    btnAdd.PostBackUrl = "~/UserLogin.aspx";
                }
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }
예제 #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["role"] == null || (string)Session["role"] != "user")
            {
                Response.Redirect("~/UserLogin.aspx");
            }
            else
            {
                userid = (int)Session["userid"];
            }
            mb = new Mybooks();
            if (Request.QueryString["id"] != null)
            {
                bid = Convert.ToInt32(Request.QueryString["id"]);
                if ((mb.Books.Where(x => x.BookID == bid).Count() > 0) &&

                    (new Work().CheckStock(bid) > 0) &&

                    (mb.CartBooks.Where(x => x.BookID == bid)
                     .Where(x => x.UserID == userid)
                     .Count() < 1))
                {
                    CartBook newitem = new CartBook();
                    newitem.UserID = userid;
                    newitem.BookID = bid;
                    mb.CartBooks.Add(newitem);
                    mb.SaveChanges();
                }
                Response.Redirect("~/RegisteredUsers/ViewCart.aspx");
            }
            using (mb)
            {
                int         count = mb.CartBooks.Where(x => x.UserID == userid).Count();
                List <Book> cart  = mb.CartBooks.Where(x => x.UserID == userid)
                                    .Select(x => x.Book).ToList();
                if (count > 0)
                {
                    Session["cartitems"] = cart;

                    Work   o = new Work();
                    double checkDiscountValue = o.GetDiscountRate(DateTime.Today.Date);
                    if (checkDiscountValue > 0)
                    {
                        DiscountLabel.Visible = true;
                        DiscountLabel.Text    = "You have a discount of " + (checkDiscountValue * 100) + "%";
                    }
                    else
                    {
                        DiscountLabel.Visible = false;
                    }

                    cartstatus.InnerText = count + " book(s) in cart.";
                    double discount = new Work().GetDiscountRate(DateTime.Today.Date);
                    foreach (Book b in cart)
                    {
                        double price  = (double)b.Price;
                        double amount = price - (price * discount);

                        HtmlGenericControl newDiv   = new HtmlGenericControl("DIV");
                        HtmlGenericControl details  = new HtmlGenericControl("DIV");
                        HtmlGenericControl imagediv = new HtmlGenericControl("DIV");
                        HtmlGenericControl third    = new HtmlGenericControl("DIV");
                        Image  img = new Image();
                        Button btn = new Button();

                        newDiv.Attributes["class"] = "row well";

                        img.ImageUrl = "~/images/" + b.ISBN + ".jpg";
                        img.Style.Add("position", "relative");
                        img.Style.Add("float", "right");
                        img.Style.Add("margin-right", "40px");

                        imagediv.Attributes["class"] = "col-xs-4 col-sm-4 col-md-4";

                        details.InnerHtml = "<br /><br /><br />" +
                                            "<strong>" + b.Title + "</strong>" +
                                            "<br /><br />" + b.Author +
                                            "<br /><br />" + price.ToString();
                        details.Attributes["class"] = "col-xs-6 col-sm-6 col-md-6";

                        third.InnerHtml = "<br /><br />" +
                                          "<p class=\"text-center\" style=\"font-size: 200%\"><strong>" +
                                          String.Format("{0:c}", amount) +
                                          "</strong></p>";
                        third.InnerHtml          += "<br /><br /><br />";
                        third.Attributes["class"] = "col-xs-2 col-sm-2 col-md-2";

                        btn.Text = "Remove";
                        btn.ID   = b.BookID.ToString();
                        btn.Attributes.Add("class", "btn btn-danger");
                        btn.Click += BtnClick;


                        cartdiv.Controls.Add(newDiv);
                        newDiv.Controls.Add(imagediv);
                        imagediv.Controls.Add(img);
                        newDiv.Controls.Add(details);
                        newDiv.Controls.Add(third);
                        third.Controls.Add(btn);
                    }
                    LblTotal.Text = "Total ~ " + String.Format("{0:c}",
                                                               new Work().CalculateTotal(cart));
                }
                else
                {
                    cartstatus.InnerText = "There is no book in cart.";
                    btncheckout.Enabled  = false;
                }
            }
        }
예제 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Session["userauth"] == null )
            //{
            //    Response.Redirect("~/AdminLogin.aspx");
            //}
            if (!IsPostBack)
            {
                using (Mybooks mb = new Mybooks())
                {
                    List <Book> booklist = mb.Books.ToList();
                    foreach (Book bookdetail in booklist)
                    {
                        HtmlGenericControl newDiv  = new HtmlGenericControl("DIV");
                        HtmlGenericControl details = new HtmlGenericControl("DIV");
                        HtmlInputImage     image   = new HtmlInputImage();
                        HtmlAnchor         anch    = new HtmlAnchor();
                        HtmlAnchor         btncart = new HtmlAnchor();

                        image.Src      = "images/" + bookdetail.ISBN + ".jpg";
                        image.Disabled = true;
                        image.Style.Add("width", "200px");
                        image.Style.Add("height", "220px");

                        anch.InnerHtml = "<hr><strong style=\"font-size: 16px;\">"
                                         + bookdetail.Title + "</strong><br />";

                        details.InnerHtml += bookdetail.Author + "<br />";
                        details.InnerHtml += bookdetail.ISBN + "<br />";
                        details.InnerHtml += "$ " + bookdetail.Price;

                        newDiv.Attributes.Add("class", "col-xs-12 col-sm-6 col-md-4 well");
                        newDiv.Style.Add("height", "500px");
                        newDiv.Style.Add("text-align", "center");
                        newDiv.Style.Add("padding", "30px");

                        btncart.InnerText = "Add to Cart";
                        btncart.Attributes.Add("class", "btn btn-primary");
                        btncart.Style.Add("position", "absolute");
                        btncart.Style.Add("top", "86%");
                        btncart.Style.Add("left", "36%");
                        btncart.ID = bookdetail.BookID.ToString();


                        anch.HRef = "~/RegisteredUsers/BookDetails.aspx?id=" + bookdetail.BookID;

                        // user access
                        if (mb.CartBooks.Where(x => (x.UserID == 1) &&

                                               (x.BookID == bookdetail.BookID)).Count() > 0)
                        {
                            btncart.InnerText     = "Already in cart!";
                            btncart.Style["left"] = "33%";
                            btncart.Disabled      = true;
                        }
                        else if (new Work().CheckStock(bookdetail.BookID) < 1)
                        {
                            btncart.InnerText           = "Out of Stock";
                            btncart.Attributes["class"] = "btn btn-danger";
                            btncart.Disabled            = true;
                        }
                        else
                        {
                            btncart.HRef = "~/RegisteredUsers/ViewCart.aspx?id=" + bookdetail.BookID;
                        }

                        mainDiv.Controls.Add(newDiv);
                        newDiv.Controls.Add(image);
                        newDiv.Controls.Add(anch);
                        newDiv.Controls.Add(details);
                        newDiv.Controls.Add(btncart);
                    }
                }
            }
            else
            {
                testlbl.InnerText = "Changed";
            }
        }
예제 #14
0
        public static List <Category> ListCategory()
        {
            Mybooks entities = new Mybooks();

            return(entities.Categories.ToList <Category>());
        }