public NotificationResult Salvar(Jogador entidade) { var NotificationResult = new NotificationResult(); try { if (entidade.CodJogador != 0) { entidade.CodJogador = entidade.CodJogador; if (NotificationResult.IsValid) { _jogadorRepositorio.Adicionar(entidade); NotificationResult.Add("Cadastrado!"); } return(NotificationResult); } else { return(NotificationResult.Add(new NotificationError("Erro no cadastro!", NotificationErrorType.USER))); }; } catch (Exception ex) { return(NotificationResult.Add(new NotificationError(ex.Message))); } }
public IActionResult Post([FromBody] Jogador jogador) { try { jogador.Validar(); if (!jogador.Valido) { return(BadRequest(jogador.ObterMensagensValidacao())); } if (jogador.Id > 0) { _jogadorRepositorio.Atualizar(jogador); } else { _jogadorRepositorio.Adicionar(jogador); } return(Created("api/jogador", jogador)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }