예제 #1
0
 public ActionResult GetOrder(int orderID)
 {
     var repo = new NorthwindsRepo();
     Order order = new Order();
     order = repo.GetByIdStoredProcedure(orderID);
     return View(order);
 }
예제 #2
0
        public ActionResult GetOrder()
        {
            int orderID = int.Parse(Request.Form["orderID"]);

            var repo = new NorthwindsRepo();
            Order order = new Order();
            order = repo.GetByIdStoredProcedure(orderID);
            return View(order);
        }
예제 #3
0
        public Order GetByIdStoredProcedure(int orderId)
        {
            Order order = new Order();

            using (var cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand();
                cmd.CommandText = "OrderInfoByID";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Connection = cn;
                cmd.Parameters.AddWithValue("@OrderID", orderId);

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {

                    while (dr.Read())
                    {
                        if (order.OrderID == null)
                        {
                            order.OrderID = (int)(dr["OrderID"]);
                            order.CustomerID = dr["CustomerID"].ToString();
                            order.CompanyName = dr["CompanyName"].ToString();
                            order.OrderDate = (DateTime)(dr["OrderDate"]);
                        }

                        order.Products.Add(PopulateProductsFromDataReader(dr));
                    }

                    order.Total = order.Products.Sum(p => p.ProdTotalCost);
                }
            }

            return order;
        }