Exemple #1
0
        public bool Update(UserDetails ud, out string error)
        {
            string sqlString = "UPDATE Tbl_Users SET Us_Username = @username, Us_Email = @email, Us_PostalCode = @postalcode WHERE Us_Id = @id";

            sql.SetCommand(sqlString);
            sql.AddIntParamter("id", ud.Id);
            sql.AddStringParameter("username", 20, ud.Username);
            sql.AddStringParameter("email", 20, ud.Email);
            sql.AddIntParamter("postalcode", ud.PostalCode);

            return(sql.Execute(out error));
        }
        public bool InsertLocation(LocationDetails ld, out string error)
        {
            string sqlCheck = "SELECT COUNT(*) FROM Tbl_Locations WHERE Loc_PostalCode = @postalcode";

            sql.SetCommand(sqlCheck);
            sql.AddIntParamter("postalcode", ld.PostalCode);
            if ((int)sql.ExecuteScalar(out error) != 0)
            {
                return(Update(ld, out error));
            }


            string sqlPostalCode = "INSERT INTO Tbl_Locations (Loc_PostalCode, Loc_Location) VALUES (@postalcode, @location)";

            sql.SetCommand(sqlPostalCode);
            sql.AddStringParameter("location", 20, ld.Location);
            sql.AddIntParamter("postalcode", ld.PostalCode);

            return(sql.Execute(out error));
        }
        public List <GameData> GetUsersGames(int userId, out string error)
        {
            var    games     = new List <GameData>();
            string sqlString = "SELECT Bg_Name, Bg_Published, Bg_Id, Bgc_Id FROM Tbl_BoardGameCopys, Tbl_BoardGames WHERE Bg_Id = Bgc_CopyOfBoardGameId AND Bgc_OwnerUserId = @userId";

            try
            {
                _sqlHandler.SetCommand(sqlString);
                _sqlHandler.AddIntParamter("userId", userId);
                using (SqlDataReader reader = _sqlHandler.ExecuteReader(out error))
                {
                    while (reader.Read())
                    {
                        var game = new GameData();
                        game.GameName   = reader["Bg_Name"].ToString();
                        game.GameCopyId = (int)reader["Bgc_Id"];
                        game.Published  = (DateTime)reader["Bg_Published"];
                        game.GameId     = (int)reader["Bg_Id"];
                        games.Add(game);
                    }
                }
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            finally
            {
                _sqlHandler.EndReader();
            }
            return(games);
        }