|
@@ -25,6 +25,9 @@ namespace UnivateProperties_API.Repository.Communication
|
25
|
25
|
MailRecipient GetMailRecipientById(int id);
|
26
|
26
|
void UpdateMailRecipient(MailRecipient rec);
|
27
|
27
|
void DeleteMailRecipient(int id);
|
|
28
|
+
|
|
29
|
+ List<MailModel> GetEnquireNowLog();
|
|
30
|
+ List<MailModel> GetContactUsLog();
|
28
|
31
|
}
|
29
|
32
|
|
30
|
33
|
public class MailRepository : IMailRepository
|
|
@@ -41,9 +44,10 @@ namespace UnivateProperties_API.Repository.Communication
|
41
|
44
|
}
|
42
|
45
|
|
43
|
46
|
public void ContactUs(MailModel mm)
|
44
|
|
- {
|
|
47
|
+ {
|
45
|
48
|
var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").Where(y => y.IsDeleted == false).ToList();
|
46
|
|
- string body = _dbContext.Templates.Where(x => x.Name == "ContactUs").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
|
|
49
|
+ string body = _dbContext.Templates.Where(x => x.Name == "ContactUs").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
|
|
50
|
+ string error = "";
|
47
|
51
|
|
48
|
52
|
body = body.Replace("[FULLNAME]", mm.Name);
|
49
|
53
|
body = body.Replace("[USEREMAIL]", mm.Email);
|
|
@@ -67,40 +71,54 @@ namespace UnivateProperties_API.Repository.Communication
|
67
|
71
|
toList = toList.Substring(0, toList.Length - 2);
|
68
|
72
|
}
|
69
|
73
|
|
70
|
|
- var host = _dbContext.Hosts.FirstOrDefault();
|
71
|
|
- using (SmtpClient smtp = new SmtpClient(host.Host))
|
|
74
|
+ try
|
72
|
75
|
{
|
73
|
|
- MailMessage mail = new MailMessage();
|
74
|
|
- mail.To.Add(toList);
|
75
|
|
- mail.Subject = "Uni-Vate - New Contact Request";
|
76
|
|
- mail.Body = body;
|
77
|
|
- mail.IsBodyHtml = true;
|
78
|
|
- mail.BodyEncoding = Encoding.ASCII;
|
79
|
|
- mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
|
80
|
|
- mail.Sender = new MailAddress(host.User, "UniVate Properties");
|
81
|
|
- mail.From = new MailAddress(mm.Email, mm.Name);
|
82
|
|
-
|
83
|
|
- smtp.UseDefaultCredentials = host.NeedsAuthorize;
|
84
|
|
- smtp.Credentials = host.GetNetworkCredential();
|
85
|
|
- smtp.EnableSsl = host.UseSSL;
|
86
|
|
- smtp.Send(mail);
|
87
|
|
- }
|
|
76
|
+ var host = _dbContext.Hosts.FirstOrDefault();
|
|
77
|
+ using (SmtpClient smtp = new SmtpClient(host.Host))
|
|
78
|
+ {
|
|
79
|
+ MailMessage mail = new MailMessage();
|
|
80
|
+ mail.To.Add(toList);
|
|
81
|
+ mail.Subject = "Uni-Vate - New Contact Request";
|
|
82
|
+ mail.Body = body;
|
|
83
|
+ mail.IsBodyHtml = true;
|
|
84
|
+ mail.BodyEncoding = Encoding.ASCII;
|
|
85
|
+ mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
|
|
86
|
+ mail.Sender = new MailAddress(host.User, "UniVate Properties");
|
|
87
|
+ mail.From = new MailAddress(mm.Email, mm.Name);
|
|
88
|
+
|
|
89
|
+ smtp.UseDefaultCredentials = host.NeedsAuthorize;
|
|
90
|
+ smtp.Credentials = host.GetNetworkCredential();
|
|
91
|
+ smtp.EnableSsl = host.UseSSL;
|
|
92
|
+ smtp.Send(mail);
|
|
93
|
+ }
|
|
94
|
+ error = "None";
|
|
95
|
+ }
|
|
96
|
+ catch (Exception ex)
|
|
97
|
+ {
|
|
98
|
+ error = ex.ToString();
|
|
99
|
+ }
|
|
100
|
+ mm.ComType = "Contact Us";
|
|
101
|
+ mm.Error = error;
|
|
102
|
+ _dbContext.CommunicationLog.Add(mm);
|
|
103
|
+ _dbContext.SaveChanges();
|
88
|
104
|
}
|
89
|
105
|
|
90
|
106
|
public void EnquireNow(MailModel mm)
|
91
|
|
- {
|
|
107
|
+ {
|
92
|
108
|
var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").Where(y => y.IsDeleted == false).ToList();
|
93
|
109
|
string body = _dbContext.Templates.Where(x => x.Name == "EnquireNow").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
|
94
|
110
|
var property = _dbContext.Properties.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
|
|
111
|
+ string error = "";
|
95
|
112
|
|
96
|
|
- body = body.Replace("[FULLNAME]", mm.Name);
|
97
|
|
- body = body.Replace("[USEREMAIL]", mm.Email);
|
98
|
|
- body = body.Replace("[USERCELLPHONE]", mm.Phone);
|
99
|
|
- body = body.Replace("[PROPERTYID]", mm.Property);
|
|
113
|
+ body = body.Replace("[FULLNAME]", " " + mm.Name);
|
|
114
|
+ body = body.Replace("[USEREMAIL]", " " + mm.Email);
|
|
115
|
+ body = body.Replace("[USERCELLPHONE]", " " + mm.Phone);
|
|
116
|
+ body = body.Replace("[PROPERTYID]", " " + mm.Property);
|
100
|
117
|
body = body.Replace("[PROPERTYNAME]", property.PropertyName);
|
101
|
118
|
body = body.Replace("[PROPERTYREF]", property.PropertyRef);
|
102
|
119
|
body = body.Replace("[PROPERTYPRICE]", property.Price.ToString());
|
103
|
|
- body = body.Replace("[USERMESSAGE]", mm.Message);
|
|
120
|
+ body = body.Replace("[USERMESSAGE]", " " + mm.Message);
|
|
121
|
+ body = body.Replace("[USERHEARDFROM]", " " + mm.HeardFrom);
|
104
|
122
|
|
105
|
123
|
string toList = "";
|
106
|
124
|
int emailCount = 0;
|
|
@@ -118,24 +136,36 @@ namespace UnivateProperties_API.Repository.Communication
|
118
|
136
|
toList = toList.Substring(0, toList.Length - 2);
|
119
|
137
|
}
|
120
|
138
|
|
121
|
|
- var host = _dbContext.Hosts.FirstOrDefault();
|
122
|
|
- using (SmtpClient smtp = new SmtpClient(host.Host))
|
|
139
|
+ try
|
123
|
140
|
{
|
124
|
|
- MailMessage mail = new MailMessage();
|
125
|
|
- mail.To.Add(toList);
|
126
|
|
- mail.Subject = "Uni-Vate - Enquiry to view property";
|
127
|
|
- mail.Body = body;
|
128
|
|
- mail.IsBodyHtml = true;
|
129
|
|
- mail.BodyEncoding = Encoding.ASCII;
|
130
|
|
- mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
|
131
|
|
- mail.Sender = new MailAddress(host.User, "UniVate Properties");
|
132
|
|
- mail.From = new MailAddress(mm.Email, mm.Name);
|
133
|
|
-
|
134
|
|
- smtp.UseDefaultCredentials = host.NeedsAuthorize;
|
135
|
|
- smtp.Credentials = host.GetNetworkCredential();
|
136
|
|
- smtp.EnableSsl = host.UseSSL;
|
137
|
|
- smtp.Send(mail);
|
138
|
|
- }
|
|
141
|
+ var host = _dbContext.Hosts.FirstOrDefault();
|
|
142
|
+ using (SmtpClient smtp = new SmtpClient(host.Host))
|
|
143
|
+ {
|
|
144
|
+ MailMessage mail = new MailMessage();
|
|
145
|
+ mail.To.Add(toList);
|
|
146
|
+ mail.Subject = "Uni-Vate - Enquiry to view property";
|
|
147
|
+ mail.Body = body;
|
|
148
|
+ mail.IsBodyHtml = true;
|
|
149
|
+ mail.BodyEncoding = Encoding.ASCII;
|
|
150
|
+ mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
|
|
151
|
+ mail.Sender = new MailAddress(host.User, "UniVate Properties");
|
|
152
|
+ mail.From = new MailAddress(mm.Email, mm.Name);
|
|
153
|
+
|
|
154
|
+ smtp.UseDefaultCredentials = host.NeedsAuthorize;
|
|
155
|
+ smtp.Credentials = host.GetNetworkCredential();
|
|
156
|
+ smtp.EnableSsl = host.UseSSL;
|
|
157
|
+ smtp.Send(mail);
|
|
158
|
+ }
|
|
159
|
+ error = "None";
|
|
160
|
+ }
|
|
161
|
+ catch (Exception ex)
|
|
162
|
+ {
|
|
163
|
+ error = ex.ToString();
|
|
164
|
+ }
|
|
165
|
+ mm.ComType = "Enquire Now";
|
|
166
|
+ mm.Error = error;
|
|
167
|
+ _dbContext.CommunicationLog.Add(mm);
|
|
168
|
+ _dbContext.SaveChanges();
|
139
|
169
|
}
|
140
|
170
|
|
141
|
171
|
public void ForgotPassword(Individual toPerson, string link)
|
|
@@ -467,5 +497,16 @@ namespace UnivateProperties_API.Repository.Communication
|
467
|
497
|
_dbContext.MailRecipients.Remove(rec);
|
468
|
498
|
_dbContext.SaveChanges();
|
469
|
499
|
}
|
|
500
|
+
|
|
501
|
+ public List<MailModel> GetContactUsLog()
|
|
502
|
+ {
|
|
503
|
+ return _dbContext.CommunicationLog.Where(x => x.ComType == "Contact Us").ToList();
|
|
504
|
+ }
|
|
505
|
+
|
|
506
|
+ public List<MailModel> GetEnquireNowLog()
|
|
507
|
+ {
|
|
508
|
+ return _dbContext.CommunicationLog.Where(x => x.ComType == "Enquire Now").ToList();
|
|
509
|
+
|
|
510
|
+ }
|
470
|
511
|
}
|
471
|
512
|
}
|