Esempio n. 1
0
        private bool GetDisponibilidade(ViewModelCadastroAgendamento vm_cadastro_agendamento)
        {
            bool retorno = true;

            ServicoBusiness servico_business = new ServicoBusiness();

            try
            {
                Servico servico = servico_business.GetServico(vm_cadastro_agendamento.cadastro_agendamento_id_servico);

                DateTime date_time_inicio = DateTime.Parse(vm_cadastro_agendamento.cadastro_agendamento_data_inicio);
                DateTime data_agendamento = date_time_inicio.AddMinutes(servico.tempo);

                this.connection.Open();

                this.command.CommandText = string.Format(@"select
                                                            COUNT(*) as total,
                                                            a.*,
                                                            s.*    
                                                           from agendamento a
                                                            inner join servico s on s.id = a.id_servico
                                                           where
                                                            ('{0}' between a.data_inicio and a.data_termino
                                                            or '{1}' between a.data_inicio and a.data_termino)
                                                            and a.id_funcionario = '{2}'
                                                            and a.cancelamento = 0",
                                                         BASE_CORE.ConvertDateBrToMySql(date_time_inicio.ToString()),
                                                         BASE_CORE.ConvertDateBrToMySql(data_agendamento.ToString()),
                                                         vm_cadastro_agendamento.cadastro_agendamento_id_funcionario);
                MySqlDataReader reader = command.ExecuteReader();

                while (reader.Read())//Enquanto existir dados no select
                {
                    int total = (reader["total"].ToString() != null && reader["total"].ToString() != string.Empty) ? Int32.Parse(reader["total"].ToString()) : 0;

                    if (total > 0)
                    {
                        retorno = false;
                    }
                }


                this.connection.Close();
            }
            catch (Exception ex)
            {
                if (this.connection.State == System.Data.ConnectionState.Open)
                {
                    this.connection.Close();
                }

                retorno = false;
            }

            return(retorno);
        }
        public JsonResult <int> Cadastrar(ViewModelCadastroAgendamento vm_cadastro_agendamento)
        {
            AgendamentoBusiness agendamento_business = new AgendamentoBusiness();

            return(Json(agendamento_business.CadastrarAgendamento(vm_cadastro_agendamento)));
        }
Esempio n. 3
0
        public int CadastrarAgendamento(ViewModelCadastroAgendamento vm_cadastro_agendamento)
        {
            int retorno = 0;

            ServicoBusiness servico_business = new ServicoBusiness();

            Servico servico = servico_business.GetServico(vm_cadastro_agendamento.cadastro_agendamento_id_servico);

            DateTime date_time_inicio = DateTime.Parse(vm_cadastro_agendamento.cadastro_agendamento_data_inicio);

            vm_cadastro_agendamento.cadastro_agendamento_data_termino = date_time_inicio.AddMinutes(servico.tempo).ToString();

            if (this.GetDisponibilidade(vm_cadastro_agendamento))
            {
                try
                {
                    this.connection.Open();

                    this.command.CommandText = string.Format(@"INSERT INTO agendamento 
                                           (id_cliente,
                                            id_pet,
                                            id_servico,
                                            id_funcionario,
                                            data_inicio,
                                            data_termino,
                                            notificacao_enviada,
                                            cancelamento,
                                            ultima_alteracao,
                                            responsavel) 
                                           VALUES 
                                           ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}')",
                                                             vm_cadastro_agendamento.cadastro_agendamento_id_cliente,
                                                             vm_cadastro_agendamento.cadastro_agendamento_id_pet,
                                                             vm_cadastro_agendamento.cadastro_agendamento_id_servico,
                                                             vm_cadastro_agendamento.cadastro_agendamento_id_funcionario,
                                                             BASE_CORE.ConvertDateBrToMySql(vm_cadastro_agendamento.cadastro_agendamento_data_inicio),
                                                             BASE_CORE.ConvertDateBrToMySql(vm_cadastro_agendamento.cadastro_agendamento_data_termino),
                                                             vm_cadastro_agendamento.cadastro_agendamento_notificacao_enviada,
                                                             vm_cadastro_agendamento.cadastro_agendamento_cancelamento,
                                                             BASE_CORE.ConvertDateBrToMySql(vm_cadastro_agendamento.cadastro_agendamento_ultima_alteracao),
                                                             vm_cadastro_agendamento.cadastro_agendamento_responsavel
                                                             );
                    int insert_retorno = command.ExecuteNonQuery();

                    if (insert_retorno > 0)
                    {
                        retorno = 1;
                    }


                    this.connection.Close();
                }
                catch (Exception ex)
                {
                    if (this.connection.State == System.Data.ConnectionState.Open)
                    {
                        this.connection.Close();
                    }
                }
            }
            else
            {
                retorno = 2;
            }


            return(retorno);
        }