public ActionResult Overzicht(OrderViewModel ovm)
        {
            Klant klant = db.Klanten.Add(ovm.Klant);

            db.SaveChanges();

            Order order = new Order();

            order.Klant       = klant;
            order.OrderRegels = new List <OrderRegel>();

            db.Orders.Add(order);
            db.SaveChanges();

            foreach (var kvp in (Dictionary <int, int>)Session["Cart"])
            {
                Product product = db.Producten.Find(kvp.Key);
                int     amount  = kvp.Value;

                OrderRegel orderRegel = new OrderRegel();
                orderRegel.Order   = order;
                orderRegel.Product = product;
                orderRegel.Aantal  = amount;

                order.OrderRegels.Add(orderRegel);
            }

            db.SaveChanges();

            return(RedirectToAction("Success"));
        }
        public List <OrderViewModel> GetProductenPerOrder(int oid)
        {
            List <OrderViewModel> orders = new List <OrderViewModel>();

            try
            {
                conn.Open();

                string select = @"select * from tbl_orderregel orr join tbl_product p on orr.product_id = p.product_id join tbl_order o on orr.order_id = o.order_id where o.order_id = @id";

                MySqlCommand cmd = new MySqlCommand(select, conn);

                MySqlParameter idParam = new MySqlParameter("@id", MySqlDbType.Int32);
                idParam.Value = oid;
                cmd.Parameters.Add(idParam);

                MySqlDataReader datareader = cmd.ExecuteReader();
                while (datareader.Read())
                {
                    Product productnaam = new Product();

                    int    id        = datareader.GetInt16("order_id");
                    double totaal    = datareader.GetDouble("totaal");
                    int    gebruiker = datareader.GetInt16("gebruiker_id");

                    Order order = new Order {
                        ID = id, Totaal = totaal, StrStatus = "..", aantalProducten = 0, Gebruiker = gebruiker
                    };

                    int    productID = datareader.GetInt16("Product_ID");
                    int    aantal    = datareader.GetInt16("Aantal");
                    double subtotaal = datareader.GetDouble("Subtotaal");

                    productnaam = productdbcontroller.GetProduct(productID);

                    OrderRegel orderregel = new OrderRegel {
                        ProductID = productID, OrderID = oid, ProductNaam = productnaam.Naam, Aantal = aantal, Subtotaal = subtotaal
                    };

                    OrderViewModel orderview = new OrderViewModel {
                        Order = order, Orderregel = orderregel
                    };
                    orders.Add(orderview);
                }
                return(orders);
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }
        public IActionResult AddProduct(int aantal, int productId)
        {
            int orderId = GetSessionOrderId();

            Order      order      = orderContainer.GetByID(orderId);
            Product    product    = productContainer.GetByID(productId);
            OrderRegel orderRegel = new OrderRegel(aantal, product);

            order.EditOrderRegel(orderRegel);

            ProductViewModel productView = ProductMapper.ProductViewModel(product);

            return(RedirectToAction("Product", "Products", productView));
        }
        public List <OrderRegel> GetAllOrderRegels(int oid)
        {
            List <OrderRegel> orderregellist = new List <OrderRegel>();

            try
            {
                conn.Open();

                string       select = @"SELECT * FROM tbl_orderregel WHERE Order_ID='" + oid + "'";
                MySqlCommand cmd    = new MySqlCommand(select, conn);

                MySqlDataReader datareader = cmd.ExecuteReader();

                while (datareader.Read())
                {
                    Product productnaam = new Product();

                    int    productID = datareader.GetInt16("Product_ID");
                    int    aantal    = datareader.GetInt16("Aantal");
                    double totaal    = datareader.GetDouble("Subtotaal");

                    productnaam = productdbcontroller.GetProduct(productID);

                    OrderRegel orderregel = new OrderRegel {
                        ProductID = productID, OrderID = oid, ProductNaam = productnaam.Naam, Aantal = aantal, Subtotaal = totaal
                    };

                    orderregellist.Add(orderregel);
                }
                return(orderregellist);
            }
            catch (Exception e)
            {
                Console.WriteLine("ProductDBController GetAllProducten() " + e);
                return(null);
            }
            finally
            {
                conn.Close();
            }
        }