Refactor materials controller and push code down to the model layer.
refactored the materials controller and pushed some logic to the matrial model.