Exemplo n.º 1
0
        /// <inheritdoc />
        public bool CreateProduct(Products product)
        {
            using (var connection = new SqlConnection(ConnString))
            {
                var command = new SqlCommand("addProduct", connection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                command.Parameters.Add(ParamHelper.CreateParameter("pProductNumber", SqlDbType.Int, ParameterDirection.Input, product.ProductNumber));
                command.Parameters.Add(ParamHelper.CreateParameter("pTitle", SqlDbType.NVarChar, ParameterDirection.Input, product.Title));
                command.Parameters.Add(ParamHelper.CreateParameter("pPrice", SqlDbType.Decimal, ParameterDirection.Input, product.Price));

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }
        }