|
@@ -1,9 +1,11 @@
|
1
|
1
|
using MailKit.Net.Smtp;
|
2
|
2
|
using MimeKit;
|
3
|
3
|
using System;
|
|
4
|
+using System.Collections.Generic;
|
4
|
5
|
using System.Linq;
|
5
|
6
|
using System.Linq.Dynamic.Core;
|
6
|
7
|
using UnivateProperties_API.Context;
|
|
8
|
+using UnivateProperties_API.Helpers;
|
7
|
9
|
using UnivateProperties_API.Model.Communication;
|
8
|
10
|
|
9
|
11
|
namespace UnivateProperties_API.Repository.Communication
|
|
@@ -12,6 +14,11 @@ namespace UnivateProperties_API.Repository.Communication
|
12
|
14
|
{
|
13
|
15
|
void ContactUs(MailModel mm);
|
14
|
16
|
void EnquireNow(MailModel mm);
|
|
17
|
+ void AddRecipient(MailRecipient rec);
|
|
18
|
+ List<MailRecipient> GetMailRecipients();
|
|
19
|
+ MailRecipient GetMailRecipientById(int id);
|
|
20
|
+ void UpdateMailRecipient(MailRecipient rec);
|
|
21
|
+ void DeleteMailRecipient(int id);
|
15
|
22
|
}
|
16
|
23
|
|
17
|
24
|
public class MailRepository : IMailRepository
|
|
@@ -40,13 +47,19 @@ namespace UnivateProperties_API.Repository.Communication
|
40
|
47
|
string name = mm.Name;
|
41
|
48
|
string email = mm.Email;
|
42
|
49
|
string message = mm.Message;
|
|
50
|
+ var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").ToList();
|
43
|
51
|
|
44
|
52
|
from = new MailboxAddress("Admin", mm.FromAddress);
|
45
|
53
|
|
46
|
|
- to = new MailboxAddress("User", mm.ToAddress);
|
|
54
|
+ InternetAddressList list = new InternetAddressList();
|
|
55
|
+ foreach (var recipient in recipients)
|
|
56
|
+ {
|
|
57
|
+ list.Add(new MailboxAddress(recipient.RecipientName, recipient.RecipientMail));
|
|
58
|
+ }
|
|
59
|
+ //to = new MailboxAddress("User", mm.ToAddress);
|
47
|
60
|
|
48
|
61
|
messageObj.From.Add(from);
|
49
|
|
- messageObj.To.Add(to);
|
|
62
|
+ messageObj.To.AddRange(list);
|
50
|
63
|
|
51
|
64
|
messageObj.Subject = "Uni-Vate - New Contact Request";
|
52
|
65
|
|
|
@@ -80,13 +93,20 @@ namespace UnivateProperties_API.Repository.Communication
|
80
|
93
|
string message = mm.Message;
|
81
|
94
|
var props = _dbContext.Properties.ToList();
|
82
|
95
|
var prop = props.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
|
|
96
|
+ var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").ToList();
|
|
97
|
+
|
83
|
98
|
|
84
|
99
|
from = new MailboxAddress("Admin", mm.FromAddress);
|
85
|
100
|
|
86
|
|
- to = new MailboxAddress("User", mm.ToAddress);
|
|
101
|
+ InternetAddressList list = new InternetAddressList();
|
|
102
|
+ foreach (var recipient in recipients)
|
|
103
|
+ {
|
|
104
|
+ list.Add(new MailboxAddress(recipient.RecipientName, recipient.RecipientMail));
|
|
105
|
+ }
|
|
106
|
+ //to = new MailboxAddress("User", mm.ToAddress);
|
87
|
107
|
|
88
|
108
|
messageObj.From.Add(from);
|
89
|
|
- messageObj.To.Add(to);
|
|
109
|
+ messageObj.To.AddRange(list);
|
90
|
110
|
|
91
|
111
|
messageObj.Subject = "Uni-Vate - Enquiry to view property";
|
92
|
112
|
|
|
@@ -130,10 +150,14 @@ namespace UnivateProperties_API.Repository.Communication
|
130
|
150
|
|
131
|
151
|
bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
|
132
|
152
|
"<h4>Request to reset password</h4>" +
|
133
|
|
- "<h4>Dear " + name + " there has been a request to reset your password. If this is incorrect please send an email to info@univateproperties.co.za</h4>" +
|
|
153
|
+ "<h4>Dear " + name + ", </h4>" +
|
|
154
|
+ "<h4>There has been a request to reset your password. If this is incorrect please send an email to info@univateproperties.co.za</h4>" +
|
134
|
155
|
"<div>" +
|
|
156
|
+ "<h5>Please follow the link below to reset your password:</h5>" +
|
135
|
157
|
"<h3>"+ link + "</h3>" +
|
136
|
|
-
|
|
158
|
+ "<br />"+
|
|
159
|
+ "<h4>Thank You</h4>" +
|
|
160
|
+ "<h4>Team Uni-Vate</h4>" +
|
137
|
161
|
"</div>" +
|
138
|
162
|
"</div>" +
|
139
|
163
|
"</div>";
|
|
@@ -147,5 +171,60 @@ namespace UnivateProperties_API.Repository.Communication
|
147
|
171
|
client.Disconnect(true);
|
148
|
172
|
client.Dispose();
|
149
|
173
|
}
|
|
174
|
+
|
|
175
|
+ public void AddRecipient(MailRecipient rec)
|
|
176
|
+ {
|
|
177
|
+ if (MyCommon.IsValidEmail(rec.RecipientMail))
|
|
178
|
+ {
|
|
179
|
+ _dbContext.MailRecipients.Add(rec);
|
|
180
|
+ _dbContext.SaveChanges();
|
|
181
|
+ }
|
|
182
|
+ else
|
|
183
|
+ {
|
|
184
|
+ throw new Exception();
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ public List<MailRecipient> GetMailRecipients()
|
|
190
|
+ {
|
|
191
|
+ return _dbContext.MailRecipients.Where(x => x.IsDeleted == false).ToList();
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ public MailRecipient GetMailRecipientById(int id)
|
|
195
|
+ {
|
|
196
|
+ return _dbContext.MailRecipients.Where(x => x.Id == id).FirstOrDefault();
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ public void UpdateMailRecipient(MailRecipient rec)
|
|
200
|
+ {
|
|
201
|
+ var recipient = _dbContext.MailRecipients.Where(x => x.Id == rec.Id).FirstOrDefault();
|
|
202
|
+
|
|
203
|
+ if (recipient.RecipientMail != rec.RecipientMail)
|
|
204
|
+ {
|
|
205
|
+ recipient.RecipientMail = rec.RecipientMail;
|
|
206
|
+ }
|
|
207
|
+
|
|
208
|
+ if (recipient.RecipientName != rec.RecipientName)
|
|
209
|
+ {
|
|
210
|
+ recipient.RecipientName = rec.RecipientName;
|
|
211
|
+ }
|
|
212
|
+
|
|
213
|
+ if (recipient.RecipientUsage != rec.RecipientUsage)
|
|
214
|
+ {
|
|
215
|
+ recipient.RecipientUsage = rec.RecipientUsage;
|
|
216
|
+ }
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+ _dbContext.MailRecipients.Update(recipient);
|
|
220
|
+ _dbContext.SaveChanges();
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ public void DeleteMailRecipient(int id)
|
|
224
|
+ {
|
|
225
|
+ var rec = _dbContext.MailRecipients.Where(x => x.Id == id).FirstOrDefault();
|
|
226
|
+ _dbContext.MailRecipients.Remove(rec);
|
|
227
|
+ _dbContext.SaveChanges();
|
|
228
|
+ }
|
150
|
229
|
}
|
151
|
230
|
}
|