示例#1
0
        public List <CategoryDAL> GetCategories(int skip, int take)
        {
            List <CategoryDAL> rv = new List <CategoryDAL>();

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("GetCategories", Con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@skip", skip);
                    command.Parameters.AddWithValue("@take", take);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        CategoryMapper mapper = new CategoryMapper(reader);
                        while (reader.Read())
                        {
                            CategoryDAL c = mapper.ToCategory(reader);
                            rv.Add(c);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log(ex);
                throw;
            }
            return(rv);
        }
示例#2
0
        public CategoryDAL FindCategoryByID(int CategoryID)
        {
            CategoryDAL rv = null;

            try
            {
                EnsureConnected();
                using (SqlCommand command = new SqlCommand("FindCategoryByID", Con))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@CategoryID", CategoryID);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        CategoryMapper mapper = new CategoryMapper(reader);
                        if (reader.Read())
                        {
                            rv = mapper.ToCategory(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log(ex);
                throw;
            }
            return(rv);
        }