Пример #1
0
        public Product GetProductById(int id)
        {
            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    var commandText = "SELECT * FROM Products WHERE Id = @Id";
                    var command     = new SqlCommand(commandText, connection);
                    command.Parameters.AddWithValue("@Id", id);

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.HasRows)
                        {
                            return(null);
                        }

                        return(ProviderUtility.DataReaderMapToObject <Product>(reader));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public UserCredential GetUserCredentialByRefreshToken(string token)
        {
            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    var command = new SqlCommand(UserStoredProcedures.GetUserCredentialByRefreshToken, connection);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@RefreshToken", token);

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.HasRows)
                        {
                            return(null);
                        }

                        return(ProviderUtility.DataReaderMapToObject <UserCredential>(reader));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        public Product GetFeaturedProduct()
        {
            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    var command = new SqlCommand(ProductStoredProcedures.FeaturedProduct, connection);
                    command.CommandType = CommandType.StoredProcedure;

                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.HasRows)
                        {
                            return(null);
                        }

                        return(ProviderUtility.DataReaderMapToObject <Product>(reader));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }