Exemplo n.º 1
0
        public List <Order> GetAllOrders()
        {
            List <Order> results = null;

            //string connectionString = Configuration.GetConnectionString("DefaultConnection");
            //string connectionString = "Data Source=153.109.124.35;Initial Catalog=CrittinMeyer_ValaisEat;Persist Security Info=True;User ID=6231db;Password=Pwd46231.";

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "Select * from orders";
                    SqlCommand cmd   = new SqlCommand(query, cn);

                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (results == null)
                            {
                                results = new List <Order>();
                            }

                            Order member = new Order();

                            member.id = (int)dr["id"];
                            member.delivery_time_requested = (DateTime)dr["delivery_time_requested"];
                            // Voir si modifications souhaitées
                            CustomersDB customersDB = new CustomersDB(configuration);
                            member.customer = customersDB.GetCustomerById((int)dr["fk_customers"]);
                            DeliverersDB deliverersDB = new DeliverersDB(configuration);
                            member.deliverer = deliverersDB.GetDelivererById((int)dr["fk_deliverers"]);

                            results.Add(member);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(results);
        }
Exemplo n.º 2
0
        public Order GetOrderById(int id)
        {
            Order result = null;

            //string connectionString = Configuration.GetConnectionString("DefaultConnection");

            try
            {
                using (SqlConnection cn = new SqlConnection(connectionString))
                {
                    string     query = "Select * from orders where id=@id";
                    SqlCommand cmd   = new SqlCommand(query, cn);
                    cmd.Parameters.AddWithValue("@id", id);

                    cn.Open();

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            if (result == null)
                            {
                                result = new Order();
                            }

                            result.id = (int)dr["id"];
                            result.delivery_time_requested = (DateTime)dr["delivery_time_requested"];
                            // Voir si modifications souhaitées
                            CustomersDB customersDB = new CustomersDB(configuration);
                            result.customer = customersDB.GetCustomerById((int)dr["fk_customers"]);
                            DeliverersDB deliverersDB = new DeliverersDB(configuration);
                            result.deliverer = deliverersDB.GetDelivererById((int)dr["fk_deliverers"]);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(result);
        }