Designing functional dielectric metasurfaces for linear and nonlinear wavefront control