public List <OrderDAL> GetOrders(int skip, int take) { List <OrderDAL> proposedReturnValue = new List <OrderDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetOrders", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { OrderMapper m = new OrderMapper(reader); while (reader.Read()) { OrderDAL r = m.OrderFromReader(reader); proposedReturnValue.Add(r); } } } } catch (Exception ex) when(Log(ex)) { } return(proposedReturnValue); }
public OrderDAL FindOrderByID(int OrderID) { OrderDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindOrderByID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@OrderID", OrderID); using (SqlDataReader reader = command.ExecuteReader()) { OrderMapper m = new OrderMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = m.OrderFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 User with key {OrderID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }