-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.txt
88 lines (63 loc) · 2.29 KB
/
doc.txt
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
{
"Username": "Admin",
"UserEmail": "[email protected]",
"UserPassport": "Admin",
"UsserImage": "string",
"UserBehaviorStatus": "active",
"UserRole": "Admin",
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string connection = @"Data Source=DESKTOP-V5M8BKF;Initial Catalog=MusicCMS;User ID=sa;Password=admin1234; Integrated Security=True; ApplicationIntent=ReadWrite; MultipleActiveResultSets = True; Trusted_Connection=True;";
optionsBuilder.UseSqlServer(connection);
}
public override int SaveChanges()
{
try
{
return base.SaveChanges();
}
//catch (DbEntityValidationException vex)
//{
// var exception = HandleDbEntityValidationException(vex);
// throw exception;
//}
catch (DbUpdateException dbu)
{
var exception = HandleDbUpdateException(dbu);
Debug.WriteLine(exception.Message.ToString());
throw exception;
}
}
private Exception HandleDbUpdateException(DbUpdateException dbu)
{
var builder = new StringBuilder("A DbUpdateException was caught while saving changes. ");
try
{
foreach (var result in dbu.Entries)
{
builder.AppendFormat("Type: {0} was part of the problem.", result.Entity.GetType().FullName);
}
}
catch (Exception e)
{
builder.Append("Error parsing DbUpdateException: " + e.ToString());
}
string message = builder.ToString();
return new Exception(message, dbu);
}
public class UserAccount :IEntity
{
public UserAccount()
{
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
//public int Id{ get; set; }
[JsonProperty(PropertyName = "username")]
public string Username { get; set; }
[JsonProperty(PropertyName = "email")]
public string Useremail { get; set; }
[JsonProperty(PropertyName = "password")]
public string UserPassword { get; set; }
}