示例#1
0
        //Update statement
        public static void Update(S_Federation federation)
        {
            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 federation SET information=@information, logo=@logo WHERE id=@id ";

                    command.Parameters.AddWithValue("@id", Conversion.LongToSql(federation.id));
                    command.Parameters.AddWithValue("@information", Conversion.StringToSql(federation.information));
                    command.Parameters.AddWithValue("@logo", Conversion.StringToSql(federation.logo));

                    //Execute command
                    command.ExecuteNonQuery();

                    //close connection
                    databaseconnection.CloseConnection();
                }
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("Update, Error updating federation data: {0}", ex.Message));
            }
        }
示例#2
0
        public ActionResult Index(FederationModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to save the bond
                try
                {
                    S_Federation federation = new S_Federation();
                    federation.information = model.Information;
                    federation.id          = model.Id;
                    federation.logo        = model.UrlLogo;

                    if (!FederationManager.FederationExistById(1))
                    {
                        FederationManager.Insert(federation);
                        TempData["message"] = "De bond is toegevoegd.";
                    }
                    else
                    {
                        FederationManager.Update(federation);
                        TempData["message"] = "De bond is bijgewerkt.";
                    }

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        //Insert statement
        public static long?Insert(S_Federation federation)
        {
            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 federation (id, information, logo) VALUES (1, @information, @logo)";
                    command.Parameters.AddWithValue("@information", Conversion.StringToSql(federation.information));
                    command.Parameters.AddWithValue("@logo", Conversion.StringToSql(federation.logo));

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

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

            return(lastInsertedId.Value);
        }
示例#4
0
        private static S_Federation DataToObject(MySqlDataReader dataReader)
        {
            S_Federation federation = new S_Federation();

            federation.id          = Conversion.SqlToLongOrNull(dataReader["id"]).Value;
            federation.information = Conversion.SqlToString(dataReader["information"]);
            federation.logo        = Conversion.SqlToString(dataReader["logo"]);

            return(federation);
        }
示例#5
0
        public static S_Federation GetFederationById(long id)
        {
            S_Federation federation = 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 federation 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 list
                    if (dataReader.Read())
                    {
                        federation = DataToObject(dataReader);
                    }

                    //close Data Reader
                    dataReader.Close();

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

            return(federation);
        }
示例#6
0
        public static S_Federation GetFederation()
        {
            S_Federation federation = 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 federation LIMIT 1";

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

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

                    //close Data Reader
                    dataReader.Close();

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

            return(federation);
        }
示例#7
0
        public NbfInfo GetNbfInfo(string id)
        {
            logger.Debug(Settings.MethodName());

            NbfInfo nbfInfo = new NbfInfo();

            if (isCorrectUser(id))
            {
                try
                {
                    S_Federation federation = FederationManager.GetFederation();
                    if (federation != null)
                    {
                        nbfInfo.information = federation.information;
                        nbfInfo.logo        = Conversion.UriToEscapedUri(federation.logo);
                    }
                }
                catch
                {
                }
            }

            return(nbfInfo);
        }