public void Alterar(AlterarAgendamentoEntrada alterarEntrada) { if (alterarEntrada.Invalido || alterarEntrada.IdAgendamento != this.Id) { return; } this.IdCategoria = alterarEntrada.IdCategoria; this.IdConta = alterarEntrada.IdConta; this.IdCartaoCredito = alterarEntrada.IdCartaoCredito; this.IdPessoa = alterarEntrada.IdPessoa; this.TipoMetodoPagamento = alterarEntrada.TipoMetodoPagamento; this.Observacao = alterarEntrada.Observacao; this.Parcelas = this.CriarParcelas(alterarEntrada.QuantidadeParcelas, alterarEntrada.DataPrimeiraParcela, alterarEntrada.ValorParcela, alterarEntrada.PeriodicidadeParcelas, alterarEntrada.Observacao); }
public async Task <ISaida> AlterarAgendamento([FromBody, SwaggerParameter("Informações para alteração de um agendamento.", Required = true)] AlterarAgendamentoViewModel model) { var alterarEntrada = new AlterarAgendamentoEntrada( model.IdAgendamento.Value, model.IdCategoria.Value, model.IdConta, model.IdCartaoCredito, model.TipoMetodoPagamento.Value, model.ValorParcela.Value, model.DataPrimeiraParcela.Value, model.QuantidadeParcelas.Value, model.PeriodicidadeParcelas.Value, base.ObterIdUsuarioClaim(), model.IdPessoa, model.Observacao); return(await _agendamentoServico.AlterarAgendamento(alterarEntrada)); }
public async Task <ISaida> AlterarAgendamento(AlterarAgendamentoEntrada alterarEntrada) { // Verifica se as informações para alteração foram informadas corretamente if (alterarEntrada.Invalido) { return(new Saida(false, alterarEntrada.Mensagens, null)); } var agendamento = await _agendamentoRepositorio.ObterPorId(alterarEntrada.IdAgendamento, true); // Verifica se o agendamento existe this.NotificarSeNulo(agendamento, string.Format(AgendamentoMensagem.Id_Agendamento_Nao_Existe, alterarEntrada.IdAgendamento)); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Verifica se o agendamento pertece ao usuário informado. this.NotificarSeDiferentes(agendamento.IdUsuario, alterarEntrada.IdUsuario, AgendamentoMensagem.Agendamento_Alterar_Nao_Pertence_Usuario); if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Verifica se a categoria existe a partir do ID informado. if (agendamento.IdCategoria != alterarEntrada.IdCategoria) { this.NotificarSeFalso(await _categoriaRepositorio.VerificarExistenciaPorId(alterarEntrada.IdUsuario, alterarEntrada.IdCategoria), CategoriaMensagem.Id_Categoria_Nao_Existe); } // Verifica se a conta ou cartão de crédito existem a partir do ID informado. if (agendamento.IdConta != alterarEntrada.IdConta && alterarEntrada.IdConta.HasValue) { this.NotificarSeFalso(await _contaRepositorio.VerificarExistenciaPorId(alterarEntrada.IdUsuario, alterarEntrada.IdConta.Value), ContaMensagem.Id_Conta_Nao_Existe); } else if (alterarEntrada.IdCartaoCredito.HasValue && agendamento.IdCartaoCredito != alterarEntrada.IdCartaoCredito) { this.NotificarSeFalso(await _cartaoCreditoRepositorio.VerificarExistenciaPorId(alterarEntrada.IdUsuario, alterarEntrada.IdCartaoCredito.Value), CartaoCreditoMensagem.Id_Cartao_Nao_Existe); } // Verifica se a pessoa existe a partir do ID informado. if (agendamento.IdPessoa != alterarEntrada.IdPessoa && alterarEntrada.IdPessoa.HasValue) { this.NotificarSeFalso(await _pessoaRepositorio.VerificarExistenciaPorId(alterarEntrada.IdUsuario, alterarEntrada.IdPessoa.Value), PessoaMensagem.Id_Pessoa_Nao_Existe); } if (this.Invalido) { return(new Saida(false, this.Mensagens, null)); } // Exclui todas as parcelas abertas do agendamento. foreach (var parcelaAberta in agendamento.Parcelas.Where(x => x.Status == StatusParcela.Aberta)) { _parcelaRepositorio.Deletar(parcelaAberta); } agendamento.Alterar(alterarEntrada); _agendamentoRepositorio.Atualizar(agendamento); await _uow.Commit(); return(_uow.Invalido ? new Saida(false, _uow.Mensagens, null) : new Saida(true, new[] { AgendamentoMensagem.Agendamento_Alterado_Com_Sucesso }, new AgendamentoSaida(agendamento))); }