Пример #1
0
        public MessageResponse Cadastrar(EspacosCafe esp)
        {
            string          connectionString = Parametros.GetConnectionString();
            SqlConnection   connection       = new SqlConnection(connectionString);
            SqlCommand      command          = new SqlCommand();
            MessageResponse response         = new MessageResponse();

            command.CommandText = "insert into espacos (lotacao, horainicial, horafinal) values (@lotacao, @horainicial, @horafinal)";
            command.Parameters.AddWithValue("@lotacao", esp.Lotacao);
            command.Parameters.AddWithValue("@horainicial", esp.HoraInicial);
            command.Parameters.AddWithValue("@horafinal", esp.HoraFinal);
            command.Connection = connection;

            try
            {
                connection.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = $"Ocorreu um erro ao realizar a requisição solicitada. Erro: {ex.Message}";
                return(response);
            }
            finally
            {
                connection.Dispose();
            }

            response.Success = true;
            response.Message = "Cadastrado com sucesso.";
            return(response);
        }
Пример #2
0
        public MessageResponse Atualizar(EspacosCafe espaco)
        {
            MessageResponse response = new MessageResponse();

            response = VerificarAtualizar(espaco);
            if (response.Success)
            {
                response         = dal.Atualizar(espaco);
                response.Message = "Atualizado com sucesso!";
                return(response);
            }
            return(response);
        }
Пример #3
0
        public List <EspacosCafe> TrazerEspacosCafe()
        {
            string        connectionString = Parametros.GetConnectionString();
            SqlConnection connection       = new SqlConnection();

            connection.ConnectionString = connectionString;

            SqlCommand command = new SqlCommand();

            command.CommandText = @"select * from espacos";

            command.Connection = connection;

            List <EspacosCafe> espacos = new List <EspacosCafe>();

            try
            {
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    long     id          = Convert.ToInt64(reader["ID"]);
                    int      lotacao     = Convert.ToInt32(reader["LOTACAO"]);
                    DateTime horaInicial = Convert.ToDateTime(reader["HORAINICIAL"]);
                    DateTime horaFinal   = Convert.ToDateTime(reader["HORAFINAL"]);

                    EspacosCafe es = new EspacosCafe(id, lotacao, horaInicial, horaFinal);
                    espacos.Add(es);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                connection.Dispose();
            }

            return(espacos);
        }
Пример #4
0
        private MessageResponse VerificarAtualizar(EspacosCafe espaco)
        {
            MessageResponse response = new MessageResponse();
            List <string>   erros    = new List <string>();

            StringBuilder errosEspaco = new StringBuilder();

            if (erros.Count != 0)
            {
                for (int i = 0; i < erros.Count; i++)
                {
                    errosEspaco.AppendLine(erros[i].ToString());
                }
                response.Success = false;
                response.Message = errosEspaco.ToString();
                return(response);
            }
            response.Success = true;
            return(response);
        }