blob: a5370b12c45d0ab33104663ca0bd6e5128cea1e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.Core;
using Tango.CSV;
using System.Data.Entity;
using Tango.BL.Entities;
namespace Tango.BulkEmailModifier.CLI
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Modifying email addresses...");
var emails = CsvFile.Read<Model>(new CsvSource("Emails.csv")).ToList();
DataSource dataSource = new DataSource();
dataSource.Address = "twine.database.windows.net";
dataSource.IntegratedSecurity = false;
dataSource.UserName = "Roy";
dataSource.Password = "Aa123456";
List<String> catalogs = new List<string>()
{
"Tango_DEV",
"Tango_TEST",
"Tango_PROCESS",
"Tango_ALPHA",
"Tango_BETA",
"Tango_STAGE",
"Tango",
"Tango_BB",
};
foreach (var catalog in catalogs)
{
Console.WriteLine();
Console.WriteLine($"Switching to database {catalog}...");
Console.WriteLine();
dataSource.Catalog = catalog;
using (ObservablesContext db = ObservablesContext.CreateDefault(dataSource))
{
foreach (var email in emails)
{
var user = db.Users.Include(x => x.Contact).SingleOrDefault(x => x.Email.ToLower() == email.Old.ToLower());
if (user == null)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine($"'{email.Old}' not found.");
Console.ForegroundColor = ConsoleColor.Gray;
continue;
}
var existingNewUser = db.Users.SingleOrDefault(x => x.Email.ToLower() == email.New.ToLower());
if (existingNewUser != null)
{
Console.WriteLine($"Deleting existing new user for {existingNewUser.Email}...");
db.Users.Remove(existingNewUser);
db.SaveChanges();
}
user.Email = email.New;
if (user.Contact.Email.ToLower() == email.Old.ToLower())
{
user.Contact.Email = email.New;
}
Console.WriteLine($"Modifying {catalog} {email.Old} => {email.New}");
db.SaveChanges();
}
}
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine();
Console.WriteLine("DONE");
}
}
}
|