示例#1
0
        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);
        }
示例#2
0
        public OrderDAL OrderFromReader(SqlDataReader reader)
        {
            OrderDAL ProposedReturnValue = new OrderDAL();

            ProposedReturnValue.OrderID    = reader.GetInt32(OffsetToOrderID);
            ProposedReturnValue.OrderName  = reader.GetString(OffsetToOrderName);
            ProposedReturnValue.OrderBonus = reader.GetString(OffsetToOrderBonus);
            return(ProposedReturnValue);
        }
示例#3
0
        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);
        }