/// <summary> /// /// </summary> /// <param name="id"></param> /// <param name="filename"></param> /// <param name="type"></param> /// <returns></returns> public static int InsertPhoto(int id, string filename, PhotoType type) { string field = type == PhotoType.UserPhotos ? "User" : "Game"; return(DalHelper.Insert($"INSERT INTO {type.ToString()} ({field}, Photo) VALUES ({id}, @filename)" , new OleDbParameter("@filename", filename))); }
/// <summary> /// Inserts a user into the database /// </summary> /// <param name="email">email of the user</param> /// <param name="username">username of the user</param> /// <param name="password">plaintext password of the user</param> /// <returns>id of new user</returns> public static int InsertUser(string email, string username, string password) { return(DalHelper.Insert( "INSERT INTO Users" + "(Email,Username,HashPass)" + $"VALUES('{email}','{username}', '{BCrypt.Net.BCrypt.EnhancedHashPassword(password)}')")); }
/// <summary> /// Inserts a new game update to the database /// </summary> /// <param name="version">version name, e.g 1.12.4 or 19w34</param> /// <param name="updateName">name of update e.g "The End Update"</param> /// <param name="description">description of update, written in markdown</param> /// <param name="game">id of game</param> /// <returns>id of update</returns> public static int InsertUpdate(string version, string updateName, string description, int game) { return(DalHelper.Insert( $"INSERT INTO GameUpdates ([Update Version],[Update Name], [Update Description], [Game]) VALUES (@version,@updateName,@description,{game})", new OleDbParameter("@version", version), new OleDbParameter("@updateName", updateName), new OleDbParameter("@description", description))); }
/// <summary> /// inserts a game into the database /// </summary> /// <param name="gameName">name of game</param> /// <param name="link">link of game</param> /// <param name="description">description of game</param> /// <param name="background">background filename of game</param> /// <param name="logo">logo filename of game</param> /// <param name="developer">developer id of game</param> /// <param name="price">price of game</param> /// <returns>id of game</returns> public static int InsertGame(string gameName, string link, string description, string background, string logo, int developer, double price) { return(DalHelper.Insert( "INSERT INTO Games ([Game Name],[Game Link],Description,Background,Logo,Developer,Price) " + $"VALUES (@gameName,@link,@desc,@background,@logo,{developer},{price})", new OleDbParameter("@gameName", gameName), new OleDbParameter("@link", gameName), new OleDbParameter("@desc", gameName), new OleDbParameter("@background", gameName), new OleDbParameter("@logo", gameName))); }
/// <summary> /// Adds a user game relation to the store (happens when user buys a game) /// </summary> /// <param name="user">id of user</param> /// <param name="game">id of game</param> /// <param name="price">the cost the user paid</param> public static void AddGame(int user, int game, double price) { DalHelper.Insert($"INSERT INTO UserGames ([User],[Game],[Cost]) VALUES ({user},{game},{price});"); }
/// <summary> /// Inserts a new user activity /// </summary> /// <param name="activity">activity string</param> /// <param name="userId">id of user</param> public static void InsertActivity(string activity, int userId) { var sql = $"INSERT INTO UserActivity ([ActivityText],[User]) VALUES('{activity}',{userId})"; DalHelper.Insert(sql); }
/// <summary> /// inserts a new developer into the database /// </summary> /// <param name="developerName">name of developer</param> /// <returns></returns> public static int AddDeveloper(string developerName) { return(DalHelper.Insert("INSERT INTO Developer ([Developer Name]) VALUES (@name)", new OleDbParameter("@name", developerName))); }
/// <summary> /// inserts a game code into the database /// </summary> /// <param name="code">string of code</param> /// <param name="game">id of game</param> /// <returns>id of code row</returns> public static int InsertCode(string code, int game) { return(DalHelper.Insert($"INSERT INTO GameCodes (Code, Game) VALUES ('{code}', {game})")); }
/// <summary> /// inserts a new review into the database /// </summary> /// <param name="content">content of review</param> /// <param name="gameId">id of game</param> /// <param name="userId">id of user</param> /// <param name="stars">stars from 1-5</param> /// <returns>id of new review</returns> public static int InsertReview(string content, int gameId, int userId, int stars) { return(DalHelper.Insert( $"INSERT INTO GameReviews (Content,Game,[User],Stars) VALUES ('{content}',{gameId},{userId},{stars})")); }
/// <summary> /// Accept a friend request from user1 to user2 /// </summary> /// <param name="user1">user that sent the request</param> /// <param name="user2">user that accepted the request</param> /// <returns>if it did anything</returns> public static bool AcceptFriendRequest(int user1, int user2) { return(DalHelper.Insert( $"UPDATE UserFriends SET Type = TRUE WHERE [User 1] = {user1} AND [User 2] = {user2}") > 0); }
/// <summary> /// Sends a friend request from user1 to user2 /// </summary> /// <param name="user1">user that sends the request</param> /// <param name="user2">user that receives the request</param> public static bool SendFriendRequest(int user1, int user2) { return(DalHelper.Insert($"INSERT INTO UserFriends ([User 1], [User 2]) VALUES ({user1}, {user2})") != DbHelper.WriteDataError); }
/// <summary> /// sends an invite from developer to user /// </summary> /// <param name="user">user invited</param> /// <param name="dev">developer to invite</param> /// <returns>true if went successful</returns> public static bool SendDeveloperInvite(int user, int dev) { return(DalHelper.Insert($"INSERT INTO DeveloperInvitations ([From], [To], Fulfilled) VALUES ({dev},{user},FALSE)") != -1); }
/// <summary> /// inserts a game-genre link /// </summary> /// <param name="genreId">id of genre</param> /// <param name="gameId">id of game</param> /// <returns>id of gameGenre</returns> public static int InsertGameGenre(int genreId, int gameId) { return(DalHelper.Insert($"INSERT INTO GameGenres (Game,Genre) VALUES({gameId},{genreId})")); }