Ejemplo n.º 1
0
        public static void InsertData(Post.PostModel model)
        {
            using (var connection = new MySqlConnection("SERVER=remotemysql.com; DATABASE=Q9hz1aOZ3d; Uid=Q9hz1aOZ3d; Pwd=doh0BUmUlQ"))
            {
                connection.Open();

                try
                {
                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        var date     = DateTime.Now;
                        var datetime = date.Year + "-" + date.Month + "-" + date.Day + " " + date.Hour + ":" + date.Minute;
                        // var cmd = $"";
                        using (var command = connection.CreateCommand())
                        {
                            command.CommandText = $"Insert into Posts (Meno, Titul, Telo, Vytvorene) values (@Meno,@Titul,@Telo,@Vytvorene)";
                            command.Parameters.AddWithValue("@Meno", model.Name);
                            command.Parameters.AddWithValue("@Titul", model.Title);
                            command.Parameters.AddWithValue("@Telo", model.Body);
                            command.Parameters.AddWithValue("@Vytvorene", datetime);


                            command.ExecuteNonQuery();
                            connection.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public void OnPost()
        {
            Post.PostModel model = new Post.PostModel();
            model.Body  = Request.Form["Text"];
            model.Title = Request.Form["Title"];
            model.Name  = Request.Form["Name"];

            InsertData(model);
        }
Ejemplo n.º 3
0
        public void SelectData(Post.PostModel model)
        {
            using (var connection = new MySqlConnection("SERVER=remotemysql.com; DATABASE=Q9hz1aOZ3d; Uid=Q9hz1aOZ3d; Pwd=doh0BUmUlQ"))
            {
                connection.Open();

                try
                {
                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        var date     = DateTime.Now;
                        var datetime = date.Year + "-" + date.Month + "-" + date.Day;
                        // var cmd = $"";
                        using (var command = connection.CreateCommand())
                        {
                            command.CommandText = $"Select Meno, Titul, Telo, Vytvorene from Posts  order by Vytvorene desc";
                            using (MySqlDataReader rdr = command.ExecuteReader())
                            {
                                if (rdr.HasRows)
                                {
                                    var count = rdr.FieldCount;
                                    while (rdr.Read())
                                    {
                                        for (var i = 0; i < count; i++)
                                        {
                                            if (rdr.GetValue(i) != null)
                                            {
                                                list.Add(rdr.GetValue(i).ToString());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                connection.Close();
                ViewData["Results"] = list;

                return;
            }
        }
Ejemplo n.º 4
0
 public void OnGet()
 {
     Post.PostModel model = new Post.PostModel();
     SelectData(model);
 }