general save and update function for all entities