Exemplo n.º 1
0
        public static StrategyInfo AddNewStrategyToDB(StrategyInfo si)
        {
            SQLiteCommand sql = new SQLiteCommand();

            sql.CommandText = "INSERT INTO Strategies (Name,UserId,Script,Description,DateCreated,DateModified,Options) VALUES(@Name,@UserId,@Script,@Description,@DateCreated,@DateModified,@Options)";

            sql.Parameters.AddWithValue("@Name", si.Name);
            sql.Parameters.AddWithValue("@UserId", si.UserId);
            sql.Parameters.AddWithValue("@Script", si.Script);
            sql.Parameters.AddWithValue("@Description", si.Description);
            sql.Parameters.AddWithValue("@Options", JsonConvert.SerializeObject(new StrategyOptions()));
            sql.Parameters.AddWithValue("@DateCreated", DateTime.Now.ToSqlDateString());
            sql.Parameters.AddWithValue("@DateModified", DateTime.Now.ToSqlDateString());

            DBHelper.ExecuteSqlCommand(sql);

            // let's get the id!
            var rows   = DBHelper.dtStrategies.Rows;
            var lastId = Convert.ToInt32(rows[rows.Count - 1]["Id"]);

            si.Id = lastId;

            return(si);
        }