public static List<Order> GetOrders(int userId = 0, int restaurantId = 0) { var connection = DatabaseHandler.GetLocalDbConnection(); var command = new SqlCommand(); if (userId > 0) command.CommandText = $"SELECT * FROM [dbo].[Orders] WHERE [User] = {userId}"; else if (restaurantId > 0) command.CommandText = $"SELECT * FROM [dbo].[Orders] WHERE [Restaurant] = {restaurantId}"; else command.CommandText = "SELECT * FROM [dbo].[Orders]"; command.Connection = connection; var reader = command.ExecuteReader(); var orders = new List<Order>(); while (reader.Read()) { var order = new Order(); order.Id = (int) reader["Id"]; order.UserId = (int) reader["User"]; order.RestaurantId = (int) reader["Restaurant"]; order.Address = (string) reader["Address"]; order.Cost = Convert.ToDouble(reader["Cost"]); order.Cancelled = (bool) reader["Cancelled"]; for (var i = 0; i < 8; i++) if (!reader.IsDBNull(3 + i)) order.Add(FoodItemDatabaseHandler.GetFoodItem((int) reader["Item" + i], true)); orders.Add(order); } connection.Close(); return orders; }
public static Order GetOrder(int id, bool includeCancelled = false) { var connection = DatabaseHandler.GetLocalDbConnection(); var command = new SqlCommand(); if (includeCancelled) command.CommandText = $"SELECT * FROM [dbo].[Orders] WHERE [Id] = {id}"; else command.CommandText = $"SELECT * FROM [dbo].[Orders] WHERE [Id] = {id} AND [Cancelled] = 0"; command.Connection = connection; var reader = command.ExecuteReader(); var order = new Order(); while (reader.Read()) { order.Id = (int) reader["Id"]; order.UserId = (int) reader["User"]; order.RestaurantId = (int) reader["Restaurant"]; order.Address = (string) reader["Address"]; order.Cost = Convert.ToDouble(reader["Cost"]); order.Cancelled = (bool) reader["Cancelled"]; for (var i = 0; i < 8; i++) if (!reader.IsDBNull(3 + i)) order.Add(FoodItemDatabaseHandler.GetFoodItem((int) reader["Item" + i], true)); } connection.Close(); return order; }
public FoodItem GetFoodItem(int id, bool includeDeleted = false) { return(FoodItemDatabaseHandler.GetFoodItem(id, includeDeleted)); }