Ejemplo n.º 1
0
        public bool Insert(dataUser user) // insert new user to database according to the dataUser fields
        {
            using (var connection = new SQLiteConnection(_connectionString))
            {
                int           res     = -1;
                SQLiteCommand command = new SQLiteCommand(null, connection);
                try
                {
                    connection.Open();
                    command.CommandText = $"INSERT INTO {tableName} ( {dataUser.userEmail},{ dataUser.userNickName},{ dataUser.userPassword}, { dataUser.userBoardId}) " +
                                          $"VALUES (@email,@nickName,@password,@boardId);";

                    SQLiteParameter emailParam    = new SQLiteParameter(@"email", user.email);
                    SQLiteParameter nickNameParam = new SQLiteParameter(@"nickName", user.nickname);
                    SQLiteParameter passwordParam = new SQLiteParameter(@"password", user.password);
                    SQLiteParameter boardIdParam  = new SQLiteParameter(@"boardId", user.boardId);



                    command.Parameters.Add(emailParam);
                    command.Parameters.Add(nickNameParam);
                    command.Parameters.Add(passwordParam);
                    command.Parameters.Add(boardIdParam);

                    command.Prepare();

                    res = command.ExecuteNonQuery();
                }
                catch
                {
                    log.Warn("Insert failed");
                }
                finally
                {
                    command.Dispose();
                    connection.Close();
                }
                return(res > 0);
            }
        }
Ejemplo n.º 2
0
        protected override dal ConvertReaderToObject(SQLiteDataReader reader)// reading the data from database and create a new dataUser Object
        {
            dataUser result = new dataUser(reader.GetString(0), reader.GetString(2), reader.GetString(1), Convert.ToInt32(reader.GetValue(3)));

            return(result);
        }