move calculate totalCost from controller to model