public Tee GetTee(int id)
        {
            var t = new Tee();

            lock (locker)
            {
                connection = new SqliteConnection("Data Source=" + path);
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT [_id], [TeeName] From Tees WHERE [_id] = ?";
                    command.Parameters.Add(new SqliteParameter(DbType.Int32)
                    {
                        Value = id
                    });
                    var r = command.ExecuteReader();
                    while (r.Read())
                    {
                        t = FromReader(r);
                        break;
                    }
                }
                connection.Close();
            }
            return(t);
        }
        /// <summary>Convert from DataReader to Tee object</summary>
        Tee FromReader(SqliteDataReader r)
        {
            var t = new Tee();

            t.ID      = Convert.ToInt32(r["_id"]);
            t.TeeName = r["TeeName"].ToString();
            return(t);
        }
        public int SaveTee(Tee item)
        {
            int r;

            lock (locker)
            {
                if (item.ID != 0)
                {
                    connection = new SqliteConnection("Data Source=" + path);
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "UPDATE [Tees] SET [TeeName] = ? WHERE [_id] = ?;";
                        command.Parameters.Add(new SqliteParameter(DbType.String)
                        {
                            Value = item.TeeName
                        });
                        command.Parameters.Add(new SqliteParameter(DbType.Int32)
                        {
                            Value = item.ID
                        });
                        r = command.ExecuteNonQuery();
                    }
                    connection.Close();
                    return(r);
                }
                else
                {
                    connection = new SqliteConnection("Data Source=" + path);
                    connection.Open();
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = "INSERT INTO [Tees] ([TeeName]) VALUES (?)";
                        command.Parameters.Add(new SqliteParameter(DbType.String)
                        {
                            Value = item.TeeName
                        });
                        r = command.ExecuteNonQuery();
                    }
                    connection.Close();
                    return(r);
                }
            }
        }
Beispiel #4
0
 public static int SaveTee(Tee item)
 {
     return(CompleteGolfAppRepositoryADO.SaveTee(item));
 }
Beispiel #5
0
 public static int SaveTee(Tee item)
 {
     return(me.db.SaveTee(item));
 }