Exemple #1
0
        /// <summary>
        /// Método para mostrar los productos en la Grocery List
        /// </summary>
        /// <returns>Una lista de los productos que hay en la BD en la tabla personal</returns>
        public List <GroceryList> GroceryList()
        {
            using (IDbConnection Conexion = DbConection.Conexion())
            {
                Conexion.Open();

                SqlCommand command = new SqlCommand("spGetGroceryList", Conexion as SqlConnection);
                command.CommandType = CommandType.StoredProcedure;

                IDataReader productsReader = command.ExecuteReader();

                List <GroceryList> lstProductsPersonal = new List <GroceryList>();

                while (productsReader.Read())
                {
                    GroceryList objListProductPersonal = new GroceryList();

                    objListProductPersonal.idProducto  = Convert.ToInt32(productsReader["idProducto"]);
                    objListProductPersonal.Tag         = Convert.ToBoolean(productsReader["Tag"]);
                    objListProductPersonal.NameProduct = Convert.ToString(productsReader["NameProduct"]);
                    objListProductPersonal.Cod         = Convert.ToInt32(productsReader["Cod"]);
                    objListProductPersonal.Price       = Convert.ToInt32(productsReader["Price"]);

                    lstProductsPersonal.Add(objListProductPersonal);
                }

                return(lstProductsPersonal);
            }
        }
Exemple #2
0
        /// <summary>
        /// Método para mostrar los productos de la lista de productos
        /// </summary>
        /// <returns>Una lista de todos los productos que hay en la BD</returns>
        public List <Product> ListProducts()
        {
            using (IDbConnection Conexion = DbConection.Conexion())
            {
                Conexion.Open();

                SqlCommand command = new SqlCommand("spListProduct", Conexion as SqlConnection);
                command.CommandType = CommandType.StoredProcedure;

                IDataReader productReader = command.ExecuteReader();

                List <Product> lstProducts = new List <Product>();

                while (productReader.Read())
                {
                    Product objListProduct = new Product();

                    objListProduct.IdProduct   = Convert.ToInt32(productReader["IdProduct"]);
                    objListProduct.NameProduct = Convert.ToString(productReader["NameProduct"]);
                    objListProduct.Cod         = Convert.ToInt32(productReader["Cod"]);
                    objListProduct.Price       = Convert.ToInt32(productReader["Price"]);

                    lstProducts.Add(objListProduct);
                }

                return(lstProducts);
            }
        }
Exemple #3
0
        /// <summary>
        /// Método para insertar productos a la lista
        /// </summary>
        /// <param name="objProduct">Objeto con la información del producto a insertar</param>
        /// <returns>El resultado del query</returns>
        public int AddProductToGroceryList(int idProducto)
        {
            using (IDbConnection Conexion = DbConection.Conexion())
            {
                Conexion.Open();

                SqlCommand command = new SqlCommand("spAddProductToGroceryList", Conexion as SqlConnection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add(new SqlParameter("@pIdProducto", idProducto));

                int result = command.ExecuteNonQuery();

                return(result);
            }
        }