public async Task <ISaida> CadastrarAtalho(AtalhoEntrada entrada) { // Verifica se as informações para cadastro foram informadas corretamente if (entrada.Invalido) { return(new Saida(false, entrada.Mensagens, null)); } // Verifica se já existe um atalho com o mesmo título e URL informados this .NotificarSeVerdadeiro(await _atalhoRepositorio.VerificarExistenciaPorTitulo(entrada.IdUsuario, entrada.Titulo), AtalhoMensagem.Atalho_Com_Mesmo_Titulo) .NotificarSeVerdadeiro(await _atalhoRepositorio.VerificarExistenciaPorUrl(entrada.IdUsuario, entrada.Titulo), AtalhoMensagem.Atalho_Com_Mesma_Url); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } var atalho = new Atalho(entrada); await _atalhoRepositorio.Inserir(atalho); await _uow.Commit(); return(new Saida(true, new[] { AtalhoMensagem.Atalho_Cadastrado_Com_Sucesso }, new AtalhoSaida(atalho))); }
public async Task <IActionResult> CadastrarAtalho([FromBody, SwaggerParameter("Informações de cadastro do atalho.", Required = true)] AtalhoViewModel viewModel) { var entrada = new AtalhoEntrada( base.ObterIdUsuarioClaim(), viewModel.Titulo, viewModel.Url); return(new ApiResult(await _atalhoServico.CadastrarAtalho(entrada))); }
public void Alterar(AtalhoEntrada entrada) { if (entrada.Invalido) { return; } this.Titulo = entrada.Titulo; this.Url = entrada.Url; }
public Atalho(AtalhoEntrada entrada) { if (entrada.Invalido) { return; } this.IdUsuario = entrada.IdUsuario; this.Titulo = entrada.Titulo; this.Url = entrada.Url; }
public async Task <IActionResult> AlterarAtalho( [FromQuery, SwaggerParameter("ID do atalho.", Required = true)] int idAtalho, [FromBody, SwaggerParameter("Informações para alteração de um atalho.", Required = true)] AtalhoViewModel model) { var entrada = new AtalhoEntrada( base.ObterIdUsuarioClaim(), model.Titulo, model.Url); return(new ApiResult(await _atalhoServico.AlterarAtalho(idAtalho, entrada))); }
public async Task <ISaida> AlterarAtalho(int idAtalho, AtalhoEntrada entrada) { // Verifica se as informações para alteração foram informadas corretamente if (entrada.Invalido) { return(new Saida(false, entrada.Mensagens, null)); } var atalho = await _atalhoRepositorio.ObterPorId(idAtalho); // Verifica se o atalho existe this.NotificarSeNulo(atalho, string.Format(AtalhoMensagem.Id_Atalho_Nao_Existe, idAtalho)); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Verifica se a pessoa pertece ao usuário informado. this.NotificarSeDiferentes(atalho.IdUsuario, entrada.IdUsuario, AtalhoMensagem.Atalho_Alterar_Nao_Pertence_Usuario); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Verifica se já existe um atalho com o mesmo título e URL informados this .NotificarSeVerdadeiro(await _atalhoRepositorio.VerificarExistenciaPorTitulo(entrada.IdUsuario, entrada.Titulo, idAtalho), AtalhoMensagem.Atalho_Com_Mesmo_Titulo) .NotificarSeVerdadeiro(await _atalhoRepositorio.VerificarExistenciaPorUrl(entrada.IdUsuario, entrada.Url, idAtalho), AtalhoMensagem.Atalho_Com_Mesma_Url); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } atalho.Alterar(entrada); _atalhoRepositorio.Atualizar(atalho); await _uow.Commit(); return(new Saida(true, new[] { AtalhoMensagem.Atalho_Alterado_Com_Sucesso }, new AtalhoSaida(atalho))); }