public UserData(BaseUserData data) { id = data.id; discordId = data.discordId; userName = data.nickName; completedTournaments = new List <CompletedTournaments>(); ongoingTournaments = new List <CompletedTournaments>(); ongoingCreatedTournaments = new List <CompletedTournaments>(); completedCreatedTournaments = new List <CompletedTournaments>(); }
public static async Task <bool> CreateUser(BaseUserData value) { if (!Cryptography.CryptographyModule.IsSignatureValid(value.signature, value.id)) { return(false); } var collec = Models.DatabaseConnection.GetDb().GetCollection <UserData>("Users"); var user = (await collec.FindAsync(u => u.id == value.id.ToLower())).FirstOrDefault(); if (user == null) { value.id = value.id.ToLower(); await collec.InsertOneAsync(new UserData(value)); return(true); } else { return(false); } }
public static async Task <bool> UpdateUser(BaseUserData value) { if (!Cryptography.CryptographyModule.IsSignatureValid(value.signature, value.id)) { return(false); } var collec = Models.DatabaseConnection.GetDb().GetCollection <UserData>("Users"); var user = (await collec.FindAsync(u => u.id == value.id.ToLower())).FirstOrDefault(); if (user != null) { user.userName = value.nickName; user.discordId = value.discordId; await collec.ReplaceOneAsync(u => u.id == value.id.ToLower(), user); return(true); } else { return(false); } }