Exemple #1
0
 public OrderResponseBE GetOrderById(int orderProductId)
 {
     try
     {
         OrderResponseBE response = _orderDA.GetOrderById(orderProductId);
         response.OrderDetails = _orderDA.GetOrderDetails(orderProductId);
         return(response);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #2
0
        public List <OrderResponseBE> GetAllOrder(OrderRequestBE obj)
        {
            List <OrderResponseBE> orders = new List <OrderResponseBE>();

            using (_connection = new SqlConnection(_connectionString))
            {
                //var query = "SELECT c.*, ct.CustomerTypeName FROM Customer c " +
                //            "INNER JOIN CustomerType ct " +
                //            "ON c.CustomerTypeId = ct.CustomerTypeId";

                //var query = "SELECT [Order].OrderId, [Order].OrderDate, Customer.FirstName, Customer.LastName, CustomerType.CustomerTypeName, ( OrderDetail.UnitPrice* OrderDetail.Quantity ) AS TotalAmount " +
                //            "FROM (((( Customer INNER JOIN CustomerType ON Customer.CustomerTypeId = CustomerType.CustomerTypeId ) " +
                //            "INNER JOIN [Order] ON Customer.CustomerId = [Order].CustomerId ) " +
                //            "INNER JOIN OrderDetail ON[Order].OrderId= OrderDetail.ProductId )) " +
                //            "WHERE Customer.CustomerId = @customerId AND CustomerType.CustomerTypeId = @customerTypeId AND [Order].OrderDate = @orderDate";
                //SqlCommand command = new SqlCommand(query, _connection);

                //Connection to db passing stored procedure name
                SqlCommand command = new SqlCommand("usp_OrderDetailsOfCustomer", _connection);
                //command.CommandText = "usp_OrderDetailsOfCustomer";
                command.CommandType = CommandType.StoredProcedure;

                //InputParameters
                command.Parameters.AddWithValue("@customerId", obj.CustomerId);
                command.Parameters.AddWithValue("@customerTypeId", obj.CustomerTypeId);
                command.Parameters.AddWithValue("@orderDate", obj.OrderDate);
                try
                {
                    _connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        OrderResponseBE order = new OrderResponseBE();
                        order.OrderId          = Convert.ToInt32(reader["OrderId"]);
                        order.OrderDate        = Convert.ToDateTime(reader["OrderDate"]);
                        order.FirstName        = Convert.ToString(reader["FirstName"]);
                        order.LastName         = Convert.ToString(reader["LastName"]);
                        order.CustomerTypeName = Convert.ToString(reader["CustomerTypeName"]);
                        order.TotalAmount      = Convert.ToDouble(reader["TotalAmount"]);
                        //Adding object to the list
                        orders.Add(order);
                    }
                    reader.Close();
                    return(orders);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
        private void BindOrderDetails()
        {
            int orderProductId = Convert.ToInt32(Session["orderProductId"]);

            try
            {
                OrderResponseBE order = new OrderResponseBE();
                order = _orderBA.GetOrderById(orderProductId);
                //lblOrderDate.Text = Convert.ToString(order.OrderDate);
                //DateTime dat = Convert.ToDateTime("1986-03-24T00:00:00");
                lblOrderDate.Text          = order.OrderDate.ToString("dd-MM-yyyy");
                lblCustomerName.Text       = order.FirstName + " " + order.LastName;
                lblCustomerType.Text       = order.CustomerTypeName;
                gvwOrderDetails.DataSource = order.OrderDetails;
                gvwOrderDetails.DataBind();
            }
            catch (Exception ex)
            {
                lblError.Text = ex.ToString();
            }
        }
Exemple #4
0
        public OrderResponseBE GetOrderById(int orderId)
        {
            using (_connection = new SqlConnection(_connectionString))
            {
                var query = "SELECT [Order].OrderId, [Order].OrderDate, Customer.FirstName, Customer.LastName, CustomerType.CustomerTypeName, ( OrderDetail.UnitPrice* OrderDetail.Quantity ) AS TotalAmount " +
                            "FROM (((( Customer INNER JOIN CustomerType ON Customer.CustomerTypeId = CustomerType.CustomerTypeId ) " +
                            "INNER JOIN [Order] ON Customer.CustomerId = [Order].CustomerId ) " +
                            "INNER JOIN OrderDetail ON[Order].OrderId= OrderDetail.ProductId )) " +
                            "WHERE [Order].OrderId = @orderId";

                SqlCommand command = new SqlCommand(query, _connection);
                command.Parameters.AddWithValue("@orderId", orderId);
                //command.Parameters
                try
                {
                    _connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    reader.Read();
                    OrderResponseBE order = new OrderResponseBE();
                    order.OrderId          = Convert.ToInt32(reader["OrderId"]);
                    order.CustomerTypeName = Convert.ToString(reader["CustomerTypeName"]);
                    order.FirstName        = Convert.ToString(reader["FirstName"]);
                    order.LastName         = Convert.ToString(reader["LastName"]);
                    order.OrderDate        = Convert.ToDateTime(reader["OrderDate"]);
                    order.TotalAmount      = Convert.ToDouble(reader["TotalAmount"]);

                    //Adding object to the list
                    reader.Close();

                    _connection.Close();
                    return(order);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }