public ActionResult DeleteSong(int SongId) { var song = _songService.GetById(SongId); if (CanDelete(song)) { //the logged in user can delete the page. lets delete the associated things now while (song.Pictures.Count() != 0) { foreach (var songpicture in song.Pictures) { var picture = _pictureService.GetPictureById(songpicture.PictureId); _songService.DeletePicture(songpicture); _pictureService.DeletePicture(picture); //collection modified. so better break the loop and let it run agian. break; } } _songService.Delete(song); return(Json(new { Success = true })); } else { return(Json(new { Success = false, Message = "Unauthorized" })); } }