Modelling the prompt and afterglow emission of gamma-ray bursts