public virtual T Registrar(T obj) { if (obj == null) { throw new ArgumentNullException($"Deve ser informado um registro válido e não nulo para ser registrado no repositório."); } obj = AntesDeRegistrar?.Invoke(obj) ?? obj; if (Registrado(obj)) { throw new BllExcecao($"Já existe um registro com estes dados.\nRegistro: {obj.ToString()}"); } if (RegistradoEExcluido(obj)) { throw new BllExcecao($"Já existe um registro com estes dados. No entanto ele foi excluido. Exclua-o permanentemente primeiro.\nRegistro: {obj.ToString()}"); } dao.Inserir(obj); obj = DepoisDeRegistrar?.Invoke(obj) ?? obj; return(obj); }