public bool Salvar(AgendamentoInfo agendamentoInfo)
        {
            Acessor acessor = new Acessor();
            bool    sucesso = true;

            try
            {
                using (TransactionScope transacao = new TransactionScope())
                {
                    if (ValidaAgendamento(agendamentoInfo))
                    {
                        if (agendamentoInfo.IsNew)
                        {
                            sucesso = acessor.AgendamentoDal.Inserir(agendamentoInfo);
                        }
                        else if (agendamentoInfo.IsDirty)
                        {
                            sucesso = acessor.AgendamentoDal.Editar(agendamentoInfo);
                        }
                    }
                    transacao.Complete();
                }
                return(sucesso);
            }
            catch (Exception exc)
            {
                throw new Exception(exc.Message, exc);
            }
            finally
            {
                acessor = null;
            }
        }
Example #2
0
        public CommandResponse AdicionarAgendamento(AgendamentoInfo obj)
        {
            try
            {
                _contexto.Connection.Open();
                _contexto.BeginTransaction();
                var query = AgendamentoInfoQueries.InsertAgendamentoInfo();

                var param = new DynamicParameters();
                param.Add(name: "IdProcesso", value: obj.IdProcesso.ToString(), direction: ParameterDirection.Input);
                if (obj.DataInicio != DateTime.MinValue)
                {
                    param.Add(name: "DataInicio", value: obj.DataInicio, direction: ParameterDirection.Input);
                }
                else
                {
                    param.Add(name: "DataInicio", value: null, direction: ParameterDirection.Input);
                }


                param.Add(name: "Descricao", value: obj.Descricao, direction: ParameterDirection.Input);
                param.Add(name: "NomeAgente", value: obj.NomeAgente, direction: ParameterDirection.Input);
                param.Add(name: "Periodicidade", value: obj.Periodicidade.ToString(), direction: ParameterDirection.Input);
                param.Add(name: "FrequenciaPeriodicidade", value: obj.FrequenciaPeriodicidade, direction: ParameterDirection.Input);
                param.Add(name: "StatusAgendamento", value: obj.StatusAgendamento.ToString(), direction: ParameterDirection.Input);
                param.Add(name: "HoraInicio", value: obj.HoraInicio.ToString(), direction: ParameterDirection.Input);
                param.Add(name: "MinutoInicio", value: obj.MinutoInicio.ToString(), direction: ParameterDirection.Input);
                param.Add(name: "AmPm", value: obj.AmPm, direction: ParameterDirection.Input);
                param.Add(name: "Ativo", value: obj.Ativo, direction: ParameterDirection.Input);
                param.Add(name: "DisparoManual", value: obj.DisparoManual, direction: ParameterDirection.Input);
                param.Add(name: "Path_UltimaExecucao", value: obj.MinutoInicio.ToString(), direction: ParameterDirection.Input);

                _contexto.Connection.Execute(query, param, _contexto.Transaction);

                query = EmailInfoQueries.InsertEmailInfoPorId();
                param = new DynamicParameters();
                param.Add(name: "IdProcesso", value: obj.IdProcesso.ToString(), direction: ParameterDirection.Input);
                param.Add(name: "Assunto", value: obj.Email.Assunto, direction: ParameterDirection.Input);
                param.Add(name: "Remetente", value: obj.Email.Remetente, direction: ParameterDirection.Input);
                param.Add(name: "Destinatario", value: obj.Email.Destinatario, direction: ParameterDirection.Input);
                param.Add(name: "Destinatario_CC", value: obj.Email.Destinatario_CC, direction: ParameterDirection.Input);
                param.Add(name: "Destinatario_CO", value: obj.Email.Destinatario_CO, direction: ParameterDirection.Input);
                _contexto.Connection.Execute(query, param, _contexto.Transaction);

                _contexto.Transaction.Commit();
                _contexto.Dispose();

                return(new CommandResponse(true, $"{obj.Descricao} adicionada com sucesso"));
            }
            catch (SQLiteException ex)
            {
                _contexto.Transaction.Rollback();
                _contexto.Dispose();
                return(new CommandResponse(false, $"{ex.Message}"));
            }
        }
Example #3
0
        public CommandResponse AtualizarStatusAgendamento(AgendamentoInfo obj)
        {
            try
            {
                _contexto.Connection.Open();
                _contexto.Connection.Execute(AgendamentoInfoQueries.UpdateStatusExecucao(obj));
                _contexto.Dispose();

                return(new CommandResponse(true, $"{obj.Descricao} atualizado com sucesso"));
            }
            catch (SQLiteException ex)
            {
                _contexto.Dispose();
                return(new CommandResponse(false, $"Erro : {ex.Message}"));
            }
        }
        private bool ValidaAgendamento(AgendamentoInfo agendamentoInfo)
        {
            bool sucesso = true;

            try
            {
                if (agendamentoInfo == null)
                {
                    throw new Exception("Objeto AgendamentoInfo é nulo");
                }
            }
            catch
            {
                sucesso = false;
            }
            return(sucesso);
        }
        public AgendamentoInfo ListarPorCodigo(int age_codigo)
        {
            Acessor         acessor         = new Acessor();
            AgendamentoInfo agendamentoInfo = new AgendamentoInfo();

            try
            {
                return(agendamentoInfo = acessor.AgendamentoDal.ListarPorCodigo(age_codigo));
            }
            catch (Exception exc)
            {
                throw new Exception(exc.Message, exc);
            }
            finally
            {
                acessor = null;
            }
        }
        public bool Inserir(AgendamentoInfo agendamentoInfo)
        {
            List <SqlParameter> lParam = new List <SqlParameter>();
            bool            sucesso    = false;
            StoredProcedure sp         = null;
            SqlDataReader   dr         = null;

            try
            {
                lParam.Add(new SqlParameter(paramAGE_TAG_Codigo, agendamentoInfo.AGE_TAG_Codigo));
                lParam.Add(new SqlParameter(paramAGE_DataHoraInicio, agendamentoInfo.AGE_DataHoraInicio));
                lParam.Add(new SqlParameter(paramAGE_DataHoraFim, agendamentoInfo.AGE_DataHoraFim));
                lParam.Add(new SqlParameter(paramAGE_PRT_Codigo, agendamentoInfo.AGE_PRT_Codigo));

                using (sp = new StoredProcedure(spInserir, lParam, ConexoesBanco.PlusCondominios))
                {
                    dr = sp.GetDataReader();
                    if (dr.Read())
                    {
                        agendamentoInfo.AGE_Codigo = int.Parse(dr["AGE_Codigo"].ToString());
                        sucesso = true;
                    }
                    else
                    {
                        sucesso = false;
                    }
                }
            }
            catch (Exception exc)
            {
                sucesso = false;
                throw new Exception(exc.Message, exc);
            }
            finally
            {
                lParam = null;
                dr.Close();
            }
            return(sucesso);
        }
Example #7
0
        public CommandResponse AtualizarAgendamentoInfoPorID(AgendamentoInfo obj)
        {
            try
            {
                _contexto.Connection.Open();
                _contexto.BeginTransaction();

                _contexto.Connection.Execute(AgendamentoInfoQueries.UpdateAgendamentoInfo(obj), _contexto.Transaction);
                _contexto.Connection.Execute(EmailInfoQueries.UpdateEmailInfoPorId(obj.Email), _contexto.Transaction);

                _contexto.Transaction.Commit();
                _contexto.Dispose();

                return(new CommandResponse(true, $"{obj.Descricao} atualizado com sucesso"));
            }
            catch (SQLiteException ex)
            {
                _contexto.Transaction.Rollback();
                _contexto.Dispose();
                return(new CommandResponse(false, $"Erro : {ex.Message}"));
            }
        }
Example #8
0
 public static string UpdateStatusExecucao(AgendamentoInfo ag)
 {
     return($"UPDATE AgendamentoInfo SET  DataProximaExecucao = '{ag.DataProximaExecucao}',DataUltimaExecucao = '{ag.DataUltimaExecucao}',  StatusAgendamento = '{ag.StatusAgendamento}'  Where IdProcesso = '{ag.IdProcesso}'");
 }
Example #9
0
 public static string UpdateAgendamentoInfo(AgendamentoInfo ag)
 {
     return($"UPDATE AgendamentoInfo SET  DataInicio = '{ag.DataInicio}', DataProximaExecucao = '{ag.DataProximaExecucao}',DataUltimaExecucao = '{ag.DataUltimaExecucao}', Descricao = '{ag.Descricao}', NomeAgente = '{ag.NomeAgente}', Periodicidade = '{ag.Periodicidade}',FrequenciaPeriodicidade = {ag.FrequenciaPeriodicidade.Value}, StatusAgendamento = '{ag.StatusAgendamento}', HoraInicio = '{ag.HoraInicio}', MinutoInicio = '{ag.MinutoInicio}', Ativo = {ag.Ativo}, AmPm = '{ag.AmPm}', DisparoManual = {ag.DisparoManual}  Where IdProcesso = '{ag.IdProcesso}'");
 }