Exemplo n.º 1
0
        public ActionResult Edit(TextModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to save the text
                try
                {
                    S_Text text = TextManager.GetTextById(model.Id);

                    text.text = model.text;
                    text.id   = model.Id;

                    TextManager.Update(text);

                    return(RedirectToAction("index", "text", null));
                }
                catch (Exception e)
                {
                    TempData["error"] = "Er is een fout opgetreden";
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        //Update statement
        public static void Update(S_Text text)
        {
            try
            {
                DatabaseConnection databaseconnection = new DatabaseConnection();

                //open connection
                if (databaseconnection.OpenConnection())
                {
                    //create command and assign the query and connection from the constructor
                    MySqlCommand command = new MySqlCommand();
                    command.Connection = databaseconnection.getConnection();

                    command.CommandText = "UPDATE text SET label=@label, text=@text WHERE id=@id ";

                    command.Parameters.AddWithValue("@id", Conversion.LongToSql(text.id));
                    command.Parameters.AddWithValue("@label", Conversion.StringToSql(text.label));
                    command.Parameters.AddWithValue("@text", Conversion.StringToSql(text.text));

                    //Execute command
                    command.ExecuteNonQuery();

                    //close connection
                    databaseconnection.CloseConnection();
                }
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("Update, Error updating text data: {0}", ex.Message));
            }
        }
Exemplo n.º 3
0
        private static S_Text DataToObject(MySqlDataReader dataReader)
        {
            S_Text text = new S_Text();

            text.id    = Conversion.SqlToIntOrNull(dataReader["id"]).Value;
            text.label = Conversion.SqlToString(dataReader["label"]);
            text.text  = Conversion.SqlToString(dataReader["text"]);

            return(text);
        }
Exemplo n.º 4
0
        public ActionResult Edit(long id)
        {
            S_Text    text      = TextManager.GetTextById(id);
            TextModel textModel = new TextModel();

            textModel.Id    = text.id;
            textModel.label = text.label;
            textModel.text  = text.text;

            return(View(textModel));
        }
Exemplo n.º 5
0
        public static S_Text GetTextById(long id)
        {
            S_Text text = null;

            try
            {
                DatabaseConnection databaseconnection = new DatabaseConnection();

                //Open connection
                if (databaseconnection.OpenConnection())
                {
                    //Create Command
                    MySqlCommand command = new MySqlCommand();
                    command.Connection  = databaseconnection.getConnection();
                    command.CommandText = "SELECT * FROM text WHERE id=@id";
                    command.Parameters.AddWithValue("@id", Conversion.LongToSql(id));

                    //Create a data reader and Execute the command
                    MySqlDataReader dataReader = command.ExecuteReader();

                    //Read the data and store them in the object
                    if (dataReader.Read())
                    {
                        text = DataToObject(dataReader);
                    }

                    //close Data Reader
                    dataReader.Close();

                    //close Connection
                    databaseconnection.CloseConnection();
                }
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("GetTextsById, Error reading text data: {0}", ex.Message));
            }

            return(text);
        }
Exemplo n.º 6
0
        //Insert statement
        public static long?Insert(S_Text text)
        {
            long?lastInsertedId = null;

            try
            {
                DatabaseConnection databaseconnection = new DatabaseConnection();

                //open connection
                if (databaseconnection.OpenConnection())
                {
                    //create command and assign the query and connection from the constructor
                    MySqlCommand command = new MySqlCommand();
                    command.Connection = databaseconnection.getConnection();

                    command.CommandText = "INSERT INTO text ( label,  text) VALUES (@label, @text)";

                    command.Parameters.AddWithValue("@label", Conversion.StringToSql(text.label));
                    command.Parameters.AddWithValue("@text", Conversion.StringToSql(text.text));


                    //Execute command
                    command.ExecuteNonQuery();
                    lastInsertedId = command.LastInsertedId;

                    //close connection
                    databaseconnection.CloseConnection();
                }
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("Insert, Error inserting text data: {0}", ex.Message));
            }

            return(lastInsertedId.Value);
        }