/// <summary>Set (UPDATE) or create (INSERT) system setting.</summary> public Entities.SystemSetting SetSetting(string name, string value) { try { Entities.SystemSetting obj1 = this.GetSetting(name); obj1.Value = value; obj1.DateModified = DateTime.Now; return(this.SetSetting(obj1)); } catch (NullReferenceException) { return(CreateSetting(new Entities.SystemSetting() { Name = name, Value = value, DateModified = DateTime.Now })); } }
/// <summary>Create (INSERT) system setting.</summary> public Entities.SystemSetting CreateSetting(Entities.SystemSetting s) { using (var sqlConnection = new System.Data.SqlClient.SqlConnection(_sqlConnectionString)) using (var sqlCommand = sqlConnection.CreateCommand()) { sqlConnection.Open(); sqlCommand.CommandText = "INSERT INTO SystemSetting (Id, ApplicationName, Name, Value, DateModified) VALUES (@Id, @ApplicationName, @Name, @Value, @DateModified);"; sqlCommand.Parameters.AddWithValue("@Id", s.Id); sqlCommand.Parameters.AddWithValue("@ApplicationName", s.ApplicationName); sqlCommand.Parameters.AddWithValue("@Name", s.Name); sqlCommand.Parameters.AddWithValue("@Value", s.Value); sqlCommand.Parameters.AddWithValue("@DateModified", s.DateModified); var numRowsAffected = sqlCommand.ExecuteNonQuery(); if (numRowsAffected <= 0) { throw new Exception(String.Format("numRowsAffected:{0}", numRowsAffected)); } } return(s); }
/// <summary>Set (UPDATE) system setting.</summary> public Entities.SystemSetting SetSetting(Entities.SystemSetting s) { using (var sqlConnection = new System.Data.SQLite.SQLiteConnection(_sqlConnectionString)) using (var sqlCommand = sqlConnection.CreateCommand()) { sqlConnection.Open(); sqlCommand.CommandText = "UPDATE SystemSetting SET ApplicationName = @ApplicationName, Name = @Name, Value = @Value, DateModified = @DateModified WHERE Id = @Id;"; sqlCommand.Parameters.AddWithValue("@Id", s.Id.ToString()); sqlCommand.Parameters.AddWithValue("@ApplicationName", s.ApplicationName); sqlCommand.Parameters.AddWithValue("@Name", s.Name); sqlCommand.Parameters.AddWithValue("@Value", s.Value); sqlCommand.Parameters.AddWithValue("@DateModified", s.DateModified); var numRowsAffected = sqlCommand.ExecuteNonQuery(); if (numRowsAffected <= 0) { throw new Exception(String.Format("numRowsAffected:{0}", numRowsAffected)); } } return(s); }