Пример #1
0
    protected void ButBuy_Click(object sender, EventArgs e)
    {
        BookshopEntities context = new BookshopEntities();

        string username = User.Identity.Name;
        Guid   userid   = context.aspnet_Users.Where(x => x.UserName == username).First().UserId;

        try
        {
            try
            {
                int        noofbooks     = (int)Session["count"];
                List <int> selectedbooks = new List <int>();

                for (int i = 0; i < noofbooks; i++)
                {
                    selectedbooks.Add(Convert.ToInt32(Session["BookNo" + i.ToString()]));
                }

                //List<Book> bookListFromCat = (List<Book>)Session["???"];        //check which data type is the info coming from

                //                BookshopEntities context = new BookshopEntities();

                cartBookList = context.Books.Where(x => selectedbooks.Contains(x.BookID)).ToList();

                foreach (Book bc in cartBookList)
                {
                    bc.Stock = 0;
                    foreach (int i in selectedbooks)
                    {
                        if (i == bc.BookID)
                        {
                            bc.Stock++;
                        }
                    }
                }
            }
            catch (NullReferenceException nue)
            {            }

            ViewCartLogic vcl = new ViewCartLogic();
            int           tid = vcl.BuyCart(cartBookList, username, userid, vcl.CountPrice(cartBookList));
            if (tid == -1)
            {
                Response.Redirect("/Team13BookShop/Customer/ErrorPage.aspx", false);
                Session["count"] = 0;
                return;
            }

            Session.Add("tranid", tid);
        }
        catch (Exception ex)
        {    }

        Session["count"] = 0;
        Response.Redirect("/Team13BookShop/Customer/Transaction.aspx");
    }
Пример #2
0
    protected void ButBuy_Click(object sender, EventArgs e)
    {
        BookshopEntities context = new BookshopEntities();

        string username = User.Identity.Name;
        Guid   userid   = context.aspnet_Users.Where(x => x.UserName == username).First().UserId;

        try
        {
            try
            {
                int        noofbooks     = (int)Session["count"];
                List <int> selectedbooks = new List <int>();

                for (int i = 0; i < noofbooks; i++)
                {
                    selectedbooks.Add((int)Session["BookNo" + i.ToString()]);
                }

                //List<Book> bookListFromCat = (List<Book>)Session["???"];        //check which data type is the info coming from

//                BookshopEntities context = new BookshopEntities();

                cartBookList = context.Books.Where(x => selectedbooks.Contains(x.BookID)).ToList();

                foreach (Book bc in cartBookList)
                {
                    bc.Stock = 0;
                    foreach (int i in selectedbooks)
                    {
                        if (i == bc.BookID)
                        {
                            bc.Stock++;
                        }
                    }
                }
            }
            catch (NullReferenceException nue)
            {
                LabErrorMsg.Text = String.Format("You currently do not have any cart items. Please continue shopping!" + nue.Message);
            }

            ViewCartLogic vcl = new ViewCartLogic();

            Session.Add("tranid", vcl.BuyCart(cartBookList, username, userid, vcl.CountPrice(cartBookList)));
        }
        catch (Exception ex)
        {
            LabErrorMsg.Text = String.Format("The error is : " + ex.Message);
        }

        Session["count"] = 0;
        Response.Redirect("/Team13BookShop/Customer/Transaction.aspx"); //or whatever name of this is
    }