protected void btnPay_Click(object sender, EventArgs e)
        {
            OrderHeader order = new OrderHeader();

            order.OrderDate = DateTime.Today;
            order.Total     = (decimal)total;

            MembershipUser user   = Membership.GetUser();
            Guid           UserID = (Guid)user.ProviderUserKey;

            order.UserID = UserID.ToString();
            //order.UserID = ""; //todo
            order.Address    = txtAddress.Text;
            order.Email      = txtEmail.Text;
            order.PostalCode = Convert.ToInt32(txtPostCode.Text);
            order.Name       = txtName.Text;

            using (BooksDB entities = new BooksDB())
            {
                entities.OrderHeaders.Add(order);
                entities.SaveChanges();

                foreach (OrderDetail orddet in lstOD)
                {
                    OrderDetail odet = new OrderDetail();
                    odet.Qty        = orddet.Qty;
                    odet.UnitPrice  = orddet.UnitPrice;
                    odet.NetPrice   = orddet.NetPrice;
                    odet.BookID     = orddet.BookID;
                    odet.DiscountID = orddet.DiscountID;
                    odet.OrderID    = order.OrderID;
                    entities.OrderDetails.Add(odet);

                    Book b = new Book();
                    b        = entities.Books.Where(x => x.BookID == odet.BookID).FirstOrDefault(); //todo
                    b.Stock -= odet.Qty;
                    entities.SaveChanges();
                }
            }
            Session["cart_items"] = null;
            Response.Redirect("ConfirmOrder.aspx?orderid=" + order.OrderID);
        }
        public static void AddOrder(OrderHeader o, List <OrderDetail> od)
        {
            using (BooksDB entities = new BooksDB())
            {
                entities.OrderHeaders.Add(o);
                entities.SaveChanges();

                foreach (OrderDetail orddet in od)
                {
                    OrderDetail odet = new OrderDetail();
                    odet.Qty        = orddet.Qty;
                    odet.UnitPrice  = orddet.UnitPrice;
                    odet.NetPrice   = orddet.NetPrice;
                    odet.BookID     = orddet.BookID;
                    odet.DiscountID = orddet.DiscountID;
                    odet.OrderID    = o.OrderID;
                    entities.OrderDetails.Add(odet);
                }
                entities.SaveChanges();
            }
        }
Esempio n. 3
0
        public static void UpdateBook(Book book)
        {
            BooksDB bdb = new BooksDB();
            Book    b   = bdb.Books.Where(x => x.BookID == book.BookID).First();

            b.Title      = book.Title;
            b.Price      = book.Price;
            b.Stock      = book.Stock;
            b.Author     = book.Author;
            b.BookID     = book.BookID;
            b.CategoryID = book.CategoryID;
            b.ISBN       = book.ISBN;

            //b.Title = b.Title.Replace(s, title);

            bdb.SaveChanges();
        }