public void Editar(long id, DateTime data, long idServico, long idCliente, long idFuncionario, string guidUsuarioAgendou) { try { ClienteModel cliente = svCliente.Find(idCliente); if (cliente.IsNull()) { throw new AtendimentoInvalidoException("Cliente inválido."); } ServicoModel servico = svServico.Find(idServico); if (servico.IsNull()) { throw new AtendimentoInvalidoException("Serviço inválido."); } FuncionarioModel funcionario = svFuncionario.Find(idFuncionario); if (funcionario.IsNull()) { throw new AtendimentoInvalidoException("Funcionário inválido."); } if (funcionario.Servicos.IsNotNull()) { if (!funcionario.Servicos.ToList().Exists(s => s.Id == servico.Id)) { throw new AtendimentoInvalidoException("Este Funcionário não presta este serviço."); } } AtendimentoModel agendamentoCadastrado = _repository.GetAtendimento(cliente.Id, servico.Id, funcionario.Id, data.DateHourMinute()); if (agendamentoCadastrado.IsNotNull() && agendamentoCadastrado.Id != id) { throw new AtendimentoInvalidoException("Já existe um atendimento para este cliente com este funcionário neste horário."); } AtendimentoModel a = _repository.Find(id); if (a.IsNull()) { throw new AtendimentoInvalidoException($"Atendimento {id} não encontrado."); } a.Editar(data.DateHourMinute(), cliente, servico, funcionario, guidUsuarioAgendou, servico.Preco); _repository.Save(a); } catch (DomainException dEx) { Logger.Log.Warn(dEx); throw; } catch (Exception ex) { Logger.Log.Error(ex); throw; } }