async Task MigrateUser(User delete, User user) { user.Avatar = delete.Avatar; user.IsBanned = delete.IsBanned; user.Level = delete.Level; user.SubTier = delete.SubTier; user.UserStat.EarnedIdle += delete.UserStat.EarnedIdle; user.UserStat.Rained += delete.UserStat.Rained; user.UserStat.RainedOn += delete.UserStat.RainedOn; user.UserStat.RainedOnTotal += delete.UserStat.RainedOnTotal; user.UserStat.RainTotal += delete.UserStat.RainTotal; user.UserStat.Tip += delete.UserStat.Tip; user.UserStat.Tipped += delete.UserStat.Tipped; user.UserStat.TippedTotal += delete.UserStat.TippedTotal; user.UserStat.TipTotal += delete.UserStat.TipTotal; user.UserStat.TopRain += delete.UserStat.TopRain; user.UserStat.TopRainedOn += delete.UserStat.TopRainedOn; user.UserStat.TopTip += delete.UserStat.TopTip; user.UserStat.TopTipped += delete.UserStat.TopTipped; user.UserWallet.Balance += delete.UserWallet.Balance; user.UserWallet.CornAddy = delete.UserWallet.CornAddy; user.UserWallet.WalletServer = delete.UserWallet.WalletServer; _dbContext.Remove(delete.UserWallet); _dbContext.Remove(delete.UserIdentity); _dbContext.Remove(delete.UserStat); _dbContext.User.Remove(delete); await _dbContext.Database.ExecuteSqlRawAsync($" UPDATE [{nameof(CornTx)}] SET [{nameof(CornTx.SenderId)}] = {user.UserId} WHERE [{nameof(CornTx.SenderId)}] = {delete.UserId}"); await _dbContext.Database.ExecuteSqlRawAsync($" UPDATE [{nameof(CornTx)}] SET [{nameof(CornTx.ReceiverId)}] = {user.UserId} WHERE [{nameof(CornTx.ReceiverId)}] = {delete.UserId}"); await _dbContext.SaveAsync(); }
/// <summary> /// method to migrate pre auth0 user into current system, this is never called if user has registered with auth0 /// </summary> protected async Task MigrateOldProfile(User delete, User user) { //NOTE: this is only called for pre auth0 user profiles user.Avatar = delete.Avatar; user.IsBanned = delete.IsBanned; user.Level = delete.Level; user.SubTier = delete.SubTier; user.UserStat.EarnedIdle += delete.UserStat.EarnedIdle; user.UserStat.AmountOfRainsSent += delete.UserStat.AmountOfRainsSent; user.UserStat.AmountOfRainsReceived += delete.UserStat.AmountOfRainsReceived; user.UserStat.TotalReceivedBitcornRains += delete.UserStat.TotalReceivedBitcornRains; user.UserStat.TotalSentBitcornViaRains += delete.UserStat.TotalSentBitcornViaRains; user.UserStat.AmountOfTipsSent += delete.UserStat.AmountOfTipsSent; user.UserStat.AmountOfTipsReceived += delete.UserStat.AmountOfTipsReceived; user.UserStat.TotalReceivedBitcornTips += delete.UserStat.TotalReceivedBitcornTips; user.UserStat.TotalSentBitcornViaTips += delete.UserStat.TotalSentBitcornViaTips; user.UserStat.LargestSentBitcornRain += delete.UserStat.LargestSentBitcornRain; user.UserStat.LargestReceivedBitcornRain += delete.UserStat.LargestReceivedBitcornRain; user.UserStat.LargestSentBitcornTip += delete.UserStat.LargestSentBitcornTip; user.UserStat.LargestReceivedBitcornTip += delete.UserStat.LargestReceivedBitcornTip; user.UserWallet.Balance += delete.UserWallet.Balance; if (!string.IsNullOrEmpty(delete.UserWallet.CornAddy)) { user.UserWallet.CornAddy = delete.UserWallet.CornAddy; user.UserWallet.WalletServer = delete.UserWallet.WalletServer; } _dbContext.Remove(delete.UserWallet); _dbContext.Remove(delete.UserIdentity); _dbContext.Remove(delete.UserStat); _dbContext.User.Remove(delete); await DbOperations.ExecuteSqlRawAsync(_dbContext, $" UPDATE [{nameof(CornTx)}] SET [{nameof(CornTx.SenderId)}] = {user.UserId} WHERE [{nameof(CornTx.SenderId)}] = {delete.UserId}"); await DbOperations.ExecuteSqlRawAsync(_dbContext, $" UPDATE [{nameof(CornTx)}] SET [{nameof(CornTx.ReceiverId)}] = {user.UserId} WHERE [{nameof(CornTx.ReceiverId)}] = {delete.UserId}"); await DbOperations.ExecuteSqlRawAsync(_dbContext, $" UPDATE [{nameof(CornDeposit)}] SET [{nameof(CornDeposit.UserId)}] = {user.UserId} WHERE [{nameof(CornDeposit.UserId)}] = {delete.UserId}"); await DbOperations.ExecuteSqlRawAsync(_dbContext, $" UPDATE [{nameof(UserSubscription)}] SET [{nameof(UserSubscription.UserId)}] = {user.UserId} WHERE [{nameof(UserSubscription.UserId)}] = {delete.UserId}"); await _dbContext.SaveAsync(); }
public static void RemoveUserIfExists(BitcornContext dbContext, User user) { if (user != null) { dbContext.Database.ExecuteSqlRaw("delete socialidentity"); dbContext.Database.ExecuteSqlRaw("delete subtx"); dbContext.Database.ExecuteSqlRaw("delete corndeposit"); dbContext.Database.ExecuteSqlRaw("delete walletdownload "); var referral = dbContext.UserReferral.FirstOrDefault(u => u.UserId == user.UserId); if (referral != null) { dbContext.UserReferral.Remove(referral); } dbContext.UserSubscription.RemoveRange(dbContext.UserSubscription.Where(u => u.UserId == user.UserId).ToArray()); dbContext.WalletDownload.RemoveRange(dbContext.WalletDownload.Where(w => w.UserId == user.UserId).ToArray()); dbContext.Remove(user.UserWallet); dbContext.Remove(user.UserIdentity); dbContext.Remove(user.UserStat); dbContext.Remove(user); dbContext.SaveChanges(); } }