Bladeren bron

Multiple Updates

master
30117125 4 jaren geleden
bovenliggende
commit
f3895a9169

+ 8
- 8
UnivateProperties_API/Model/Communication/Email.cs Bestand weergeven

@@ -47,7 +47,7 @@ namespace UnivateProperties_API.Model.Communication
47 47
                     SenderId = template.SenderId.Value;
48 48
                 }
49 49
                 Sender = template.Sender;
50
-                To = "delia@lombardy6.co.za"; // sendTo.Email;
50
+                To = "jplouw@provision-sa.com"; // sendTo.Email;
51 51
                 ToDisplay = sendTo.FullName;
52 52
                 /*BCC = ConcatEmails(template.AgentBCC, template.IndividualBCC);*/
53 53
                 IsBodyHtml = true;
@@ -80,7 +80,7 @@ namespace UnivateProperties_API.Model.Communication
80 80
             
81 81
         }
82 82
 
83
-        /*public Email(Template template, Person sendTo, TimeshareWeekDto sellItem, DataContext dataContext)
83
+        public Email(Template template, Person sendTo, List<BaseEntity> args)
84 84
         {
85 85
             if (sendTo != null && MyCommon.IsValidEmail(sendTo.Email))
86 86
             {
@@ -91,12 +91,12 @@ namespace UnivateProperties_API.Model.Communication
91 91
                 Sender = template.Sender;
92 92
                 To = "jplouw@provision-sa.com"; // sendTo.Email;
93 93
                 ToDisplay = sendTo.FullName;
94
-                *//*BCC = ConcatEmails(template.AgentBCC, template.IndividualBCC);*//*
94
+                BCC = ConcatEmails(template.AgentBCC, template.IndividualBCC);
95 95
                 IsBodyHtml = true;
96
-                EmailCodedFieldsPopulator emailCodedFieldsPopulator = new EmailCodedFieldsPopulator(dataContext);
97
-                Body = emailCodedFieldsPopulator.getCodedBody(template.Body, sendTo, sellItem);
96
+                /*EmailCodedFieldsPopulator emailCodedFieldsPopulator = new EmailCodedFieldsPopulator(dataContext);*/
97
+                Body = template.Body;
98 98
                 Subject = template.Subject;
99
-                *//*foreach (var item in template.PlaceHolders)
99
+                foreach (var item in template.PlaceHolders)
100 100
                 {
101 101
                     foreach (var obj in args)
102 102
                     {
@@ -117,10 +117,10 @@ namespace UnivateProperties_API.Model.Communication
117 117
                             }
118 118
                         }
119 119
                     }
120
-                }*//*
120
+                }
121 121
             }
122 122
 
123
-        }*/
123
+        }
124 124
         #endregion Constructor
125 125
 
126 126
         #region Properties

+ 212
- 38
UnivateProperties_API/Repository/Communication/MailRepository.cs Bestand weergeven

@@ -8,6 +8,8 @@ using System.Text;
8 8
 using UnivateProperties_API.Context;
9 9
 using UnivateProperties_API.Helpers;
10 10
 using UnivateProperties_API.Model.Communication;
11
+using UnivateProperties_API.Model.ProcessFlow;
12
+using UnivateProperties_API.Model.Timeshare;
11 13
 using UnivateProperties_API.Model.Users;
12 14
 
13 15
 namespace UnivateProperties_API.Repository.Communication
@@ -38,23 +40,14 @@ namespace UnivateProperties_API.Repository.Communication
38 40
 
39 41
         public void ContactUs(MailModel mm)
40 42
         {
41
-            string property = mm.Property;
42
-            string phone = mm.Phone;
43
-            string name = mm.Name;
44
-            string email = mm.Email;
45
-            string message = mm.Message;
46
-            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").ToList();
47
-            string body = "<div style=\"margin: 5px\">" +
48
-                            "<h4>Contact from: " + name + "!</h4>" +
49
-                            "<h4>Email: " + email + "</h4>" +
50
-                            "<h4>Phone: " + phone + "</h4>" +
51
-                            "<h4>Property: " + property + "</h4>" +
52
-                            "<div>" +
53
-                            "<h4>Message: </h4>" +
54
-                            "<p>" + message + "</p>" +
55
-                            "</div>" +
56
-                            "</div>" +
57
-                            "</div>";
43
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").ToList();            
44
+            string body = _dbContext.Templates.Where(x => x.Name == "ContactUs").FirstOrDefault().Body; 
45
+
46
+            body = body.Replace("[FULLNAME]", mm.Name);
47
+            body = body.Replace("[USEREMAIL]", mm.Email);
48
+            body = body.Replace("[USERCELLPHONE]", mm.Phone);
49
+            body = body.Replace("[PROPERTYREF]", mm.Property);
50
+            body = body.Replace("[USERMESSAGE]", mm.Message);
58 51
 
59 52
             string toList = "";
60 53
             int emailCount = 0;
@@ -93,26 +86,19 @@ namespace UnivateProperties_API.Repository.Communication
93 86
         }
94 87
 
95 88
         public void EnquireNow(MailModel mm)
96
-        {            
97
-            string phone = mm.Phone;
98
-            string name = mm.Name;
99
-            string email = mm.Email;
100
-            string message = mm.Message;
101
-            var prop = _dbContext.Properties.Where(p => p.Id == int.Parse(mm.Property)).FirstOrDefault();
102
-            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").ToList();
103
-            string body = "<div style=\"margin: 5px\">" +
104
-                "<h4>Contact from: " + name + "!</h4>" +
105
-                "<h4>Email: " + email + "</h4>" +
106
-                "<h4>Phone: " + phone + "</h4>" +
107
-                "<div>" +
108
-                "<h4>Property: </h4>" +
109
-                "<p>" + prop.Id + "</p>" +
110
-                "<p>" + prop.PropertyName + "</p>" +
111
-                "<p>" + prop.PropertyRef + "</p>" +
112
-                "<p>" + prop.Price + "</p>" +
113
-                "</div>" +
114
-                "</div>" +
115
-                "</div>";
89
+        {
90
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").Where(y => y.IsDeleted == false).ToList();
91
+            string body = _dbContext.Templates.Where(x => x.Name == "EnquireNow").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
92
+            var property = _dbContext.Properties.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
93
+
94
+            body = body.Replace("[FULLNAME]", mm.Name);
95
+            body = body.Replace("[USEREMAIL]", mm.Email);
96
+            body = body.Replace("[USERCELLPHONE]", mm.Phone);
97
+            body = body.Replace("[PROPERTYID]", mm.Property);
98
+            body = body.Replace("[PROPERTYNAME]", property.PropertyName);
99
+            body = body.Replace("[PROPERTYREF]", property.PropertyRef);
100
+            body = body.Replace("[PROPERTYPRICE]", property.Price.ToString());
101
+            body = body.Replace("[USERMESSAGE]", mm.Message);
116 102
 
117 103
             string toList = "";
118 104
             int emailCount = 0;
@@ -141,7 +127,7 @@ namespace UnivateProperties_API.Repository.Communication
141 127
                 mail.BodyEncoding = Encoding.ASCII;
142 128
                 mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
143 129
                 mail.Sender = new MailAddress(host.User, "UniVate Properties");
144
-                mail.From = new MailAddress(mm.ToAddress, "Admin");
130
+                mail.From = new MailAddress(mm.Email, mm.Name);
145 131
 
146 132
                 smtp.UseDefaultCredentials = host.NeedsAuthorize;
147 133
                 smtp.Credentials = host.GetNetworkCredential();
@@ -185,6 +171,194 @@ namespace UnivateProperties_API.Repository.Communication
185 171
             }                        
186 172
         }
187 173
 
174
+        public void WeekOfferMadeOwner(TimeshareWeek week, BidItem bid)
175
+        {
176
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekOfferMade-Owner").Where(y => y.IsDeleted == false).ToList();
177
+            string body = _dbContext.Templates.Where(x => x.Name == "WeekOfferMade-Owner").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
178
+            
179
+            body = body.Replace("[OWNER]", week.DisplayOwner);
180
+            body = body.Replace("[RESORTNAME]", week.ResortName);
181
+            body = body.Replace("[UNITNUMBER]", week.UnitNumber);
182
+            body = body.Replace("[MODULE]", week.Module);
183
+            body = body.Replace("[OFFERMADE]", bid.Amount.ToString());
184
+            body = body.Replace("[FULLNAME]", bid.BidMaker.Display);
185
+            body = body.Replace("[USEREMAIL]", bid.BidMaker.Email);
186
+            body = body.Replace("[USERCELLPHONE]", bid.BidMaker.CellNumber);
187
+            body = body.Replace("[USERTELEPHONE]", bid.BidMaker.Telephone);
188
+            body = body.Replace("[USERCOMMENT]", bid.Comment);
189
+
190
+            string toList = "";
191
+            int emailCount = 0;
192
+            foreach (var recipient in recipients)
193
+            {
194
+                toList += recipient.RecipientMail + ";, ";
195
+                emailCount++;
196
+            }
197
+
198
+            if (toList.Length > 0)
199
+            {
200
+                if (emailCount == 1)
201
+                    toList = toList.Substring(0, toList.Length - 3);
202
+                else
203
+                    toList = toList.Substring(0, toList.Length - 2);
204
+            }
205
+
206
+            var host = _dbContext.Hosts.FirstOrDefault();
207
+            using (SmtpClient smtp = new SmtpClient(host.Host))
208
+            {
209
+                MailMessage mail = new MailMessage();
210
+                mail.To.Add(toList);
211
+                mail.Subject = "Uni-Vate - New Contact Request";
212
+                mail.Body = body;
213
+                mail.IsBodyHtml = true;
214
+                mail.BodyEncoding = Encoding.ASCII;
215
+                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
216
+                mail.Sender = new MailAddress(host.User, "UniVate Properties");
217
+                mail.From = mail.Sender;
218
+
219
+                smtp.UseDefaultCredentials = host.NeedsAuthorize;
220
+                smtp.Credentials = host.GetNetworkCredential();
221
+                smtp.EnableSsl = host.UseSSL;
222
+                smtp.Send(mail);
223
+            }
224
+        }
225
+
226
+        public void WeekOfferMadeUser(TimeshareWeek week, BidItem bid)
227
+        {
228
+            //var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekOfferMade-User").Where(y => y.IsDeleted == false).ToList();
229
+
230
+            string body = _dbContext.Templates.Where(x => x.Name == "WeekOfferMade-User").Where(y => y.IsDeleted == false).FirstOrDefault().Body; ;
231
+
232
+            body = body.Replace("[OWNER]", week.DisplayOwner);
233
+            body = body.Replace("[RESORTNAME]", week.ResortName);
234
+            body = body.Replace("[UNITNUMBER]", week.UnitNumber);
235
+            body = body.Replace("[MODULE]", week.Module);
236
+            body = body.Replace("[OFFERMADE]", bid.Amount.ToString());
237
+            body = body.Replace("[FULLNAME]", bid.BidMaker.Display);
238
+            body = body.Replace("[USEREMAIL]", bid.BidMaker.Email);
239
+            body = body.Replace("[USERCELLPHONE]", bid.BidMaker.CellNumber);
240
+            body = body.Replace("[USERTELEPHONE]", bid.BidMaker.Telephone);
241
+            body = body.Replace("[USERCOMMENT]", bid.Comment);
242
+
243
+
244
+
245
+            var host = _dbContext.Hosts.FirstOrDefault();
246
+            using (SmtpClient smtp = new SmtpClient(host.Host))
247
+            {
248
+                MailMessage mail = new MailMessage();
249
+                mail.To.Add(bid.BidMaker.Email);
250
+                mail.Subject = "Uni-Vate - New Contact Request";
251
+                mail.Body = body;
252
+                mail.IsBodyHtml = true;
253
+                mail.BodyEncoding = Encoding.ASCII;
254
+                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
255
+                mail.Sender = new MailAddress(host.User, "UniVate Properties");
256
+                mail.From = mail.Sender;
257
+
258
+                smtp.UseDefaultCredentials = host.NeedsAuthorize;
259
+                smtp.Credentials = host.GetNetworkCredential();
260
+                smtp.EnableSsl = host.UseSSL;
261
+                smtp.Send(mail);
262
+            }
263
+        }
264
+
265
+        public void WeekOfferMadeAdmin()
266
+        {
267
+            
268
+        }
269
+
270
+        public void WeekLoadedAgent(TimeshareWeek week)
271
+        {
272
+            string body = _dbContext.Templates.Where(x => x.Name == "WeekLoaded-Agent").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
273
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekLoaded-Agent").Where(y => y.IsDeleted == false).ToList();
274
+
275
+            body = body.Replace("[FULLNAME]", week.DisplayOwner);
276
+            body = body.Replace("[RESORTNAME]", week.ResortName);
277
+            body = body.Replace("[UNITNUMBER]", week.UnitNumber);
278
+            body = body.Replace("[MODULE]", week.Module);
279
+
280
+            string toList = "";
281
+            int emailCount = 0;
282
+            foreach (var recipient in recipients)
283
+            {
284
+                toList += recipient.RecipientMail + ";, ";
285
+                emailCount++;
286
+            }
287
+
288
+            if (toList.Length > 0)
289
+            {
290
+                if (emailCount == 1)
291
+                    toList = toList.Substring(0, toList.Length - 3);
292
+                else
293
+                    toList = toList.Substring(0, toList.Length - 2);
294
+            }
295
+
296
+            var host = _dbContext.Hosts.FirstOrDefault();
297
+            using (SmtpClient smtp = new SmtpClient(host.Host))
298
+            {
299
+                MailMessage mail = new MailMessage();
300
+                mail.To.Add(toList);
301
+                mail.Subject = "Uni-Vate - Password Reset Request";
302
+                mail.Body = body;
303
+                mail.IsBodyHtml = true;
304
+                mail.BodyEncoding = Encoding.ASCII;
305
+                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
306
+                mail.Sender = new MailAddress(host.User, "UniVate Properties");
307
+                mail.From = mail.Sender;
308
+
309
+                smtp.UseDefaultCredentials = host.NeedsAuthorize;
310
+                smtp.Credentials = host.GetNetworkCredential();
311
+                smtp.EnableSsl = host.UseSSL;
312
+                smtp.Send(mail);
313
+            }
314
+        }
315
+
316
+        public void WeekLoadedOwner(TimeshareWeek week)
317
+        {
318
+            string body = _dbContext.Templates.Where(x => x.Name == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
319
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).ToList();
320
+
321
+            body = body.Replace("[FULLNAME]", week.DisplayOwner);
322
+            body = body.Replace("[RESORTNAME]", week.ResortName);
323
+            body = body.Replace("[UNITNUMBER]", week.UnitNumber);
324
+            body = body.Replace("[MODULE]", week.Module);
325
+
326
+            string toList = "";
327
+            int emailCount = 0;
328
+            foreach (var recipient in recipients)
329
+            {
330
+                toList += recipient.RecipientMail + ";, ";
331
+                emailCount++;
332
+            }
333
+
334
+            if (toList.Length > 0)
335
+            {
336
+                if (emailCount == 1)
337
+                    toList = toList.Substring(0, toList.Length - 3);
338
+                else
339
+                    toList = toList.Substring(0, toList.Length - 2);
340
+            }
341
+
342
+            var host = _dbContext.Hosts.FirstOrDefault();
343
+            using (SmtpClient smtp = new SmtpClient(host.Host))
344
+            {
345
+                MailMessage mail = new MailMessage();
346
+                mail.To.Add(toList);
347
+                mail.Subject = "Uni-Vate - Password Reset Request";
348
+                mail.Body = body;
349
+                mail.IsBodyHtml = true;
350
+                mail.BodyEncoding = Encoding.ASCII;
351
+                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
352
+                mail.Sender = new MailAddress(host.User, "UniVate Properties");
353
+                mail.From = mail.Sender;
354
+
355
+                smtp.UseDefaultCredentials = host.NeedsAuthorize;
356
+                smtp.Credentials = host.GetNetworkCredential();
357
+                smtp.EnableSsl = host.UseSSL;
358
+                smtp.Send(mail);
359
+            }
360
+        }
361
+
188 362
         public void AddRecipient(MailRecipient rec)
189 363
         {
190 364
             if (MyCommon.IsValidEmail(rec.RecipientMail))

+ 5
- 5
UnivateProperties_API/Repository/Communication/TemplateRepository.cs Bestand weergeven

@@ -84,8 +84,8 @@ namespace UnivateProperties_API.Repository.Communication
84 84
 
85 85
         public void Update(Template item)
86 86
         {
87
-            var itemList = _dbContext.PlaceHolders.Where(x => x.TemplateId == item.Id).ToList();
88
-            CheckListChange(itemList, item.PlaceHolders.ToList());
87
+            /*var itemList = _dbContext.PlaceHolders.Where(x => x.TemplateId == item.Id).ToList();
88
+            CheckListChange(itemList, item.PlaceHolders.ToList());*/
89 89
             _dbContext.Entry(item).State = EntityState.Modified;
90 90
             Save();
91 91
         }
@@ -167,10 +167,10 @@ namespace UnivateProperties_API.Repository.Communication
167 167
                 {
168 168
                     try
169 169
                     {
170
-                        /*Email email = new Email(template, sendTo, args);
170
+                        Email email = new Email(template, sendTo, args);
171 171
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
172
-                        
173
-                        emailRepo.Insert(email);*/
172
+
173
+                        emailRepo.Insert(email);
174 174
                     }
175 175
                     catch (Exception)
176 176
                     {

+ 9
- 2
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs Bestand weergeven

@@ -250,7 +250,11 @@ namespace UnivateProperties_API.Repository.ProccessFlow
250 250
 
251 251
             var individual = _dbContext.Individuals.Where(i => i.UserId == item.UserId).FirstOrDefault();
252 252
             if (individual != null)
253
+            {
253 254
                 bid.BidMakerId = individual.Id;
255
+                bid.BidMaker = individual;
256
+            }
257
+                
254 258
 
255 259
             if (!(bid.TimeshareWeek == null && week == null))
256 260
             {
@@ -268,10 +272,12 @@ namespace UnivateProperties_API.Repository.ProccessFlow
268 272
                     if (week != null)
269 273
                     {
270 274
                         TemplateRepository templateRepository = new TemplateRepository(_dbContext);
275
+                        MailRepository mailRepository = new MailRepository(_dbContext);
271 276
                         var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-Owner");
272 277
                         if (template != null)
273 278
                         {
274
-                            templateRepository.SendEmailTemplate(template, week.Owner, list);
279
+                            mailRepository.WeekOfferMadeOwner(week, bid);
280
+                            //templateRepository.SendEmailTemplate(template, week.Owner, list);
275 281
                         }
276 282
                         template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-User");
277 283
                         if (template != null)
@@ -279,7 +285,8 @@ namespace UnivateProperties_API.Repository.ProccessFlow
279 285
                             var bidMaker = _dbContext.Individuals.FirstOrDefault(x => x.Id == bid.BidMakerId);
280 286
                             if (bidMaker != null)
281 287
                             {
282
-                                templateRepository.SendEmailTemplate(template, bidMaker, list);
288
+                                mailRepository.WeekOfferMadeUser(week, bid);
289
+                                //templateRepository.SendEmailTemplate(template, bidMaker, list);
283 290
                             }
284 291
                         }
285 292
                     }

+ 7
- 4
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Bestand weergeven

@@ -907,11 +907,12 @@ namespace UnivateProperties_API.Repository.Timeshare
907 907
             week.Region = null;
908 908
             week.RegionId = sellItem.Region.Id;
909 909
             week.OwnerId = owner.Id;
910
+            sellItem.DisplayOwner = owner.FullName;
910 911
             if (week.Mandate)
911 912
                 week.DateMandated = DateTime.Now;
912 913
 
913 914
             TemplateRepository templateRepository = new TemplateRepository(_dbContext);
914
-            
915
+            MailRepository mailRepository = new MailRepository(_dbContext);
915 916
             var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Owner");
916 917
 
917 918
             try
@@ -921,14 +922,16 @@ namespace UnivateProperties_API.Repository.Timeshare
921 922
                     template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Agent");
922 923
                     if (template != null)
923 924
                     {
924
-                        templateRepository.SendEmailTemplateWeek(template, agent, sellItem);
925
+                        mailRepository.WeekLoadedAgent(sellItem);
926
+                        //templateRepository.SendEmailTemplateWeek(template, agent, sellItem);
925 927
                     }
926 928
                 }
927 929
                 else
928 930
                 {
929 931
                     if (template != null)
930 932
                     {
931
-                        templateRepository.SendEmailTemplateWeek(template, owner, sellItem);
933
+                        mailRepository.WeekLoadedOwner(sellItem);
934
+                        //templateRepository.SendEmailTemplateWeek(template, owner, sellItem);
932 935
                     }
933 936
                     template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-UV");
934 937
                     if (template != null)
@@ -944,7 +947,7 @@ namespace UnivateProperties_API.Repository.Timeshare
944 947
             }
945 948
 
946 949
 
947
-            sellItem.DisplayOwner = owner.FullName;
950
+            
948 951
             if (sellItem.StatusId == 0) 
949 952
                 week.StatusId = 32;
950 953
             _dbContext.Add(week);

Laden…
Annuleren
Opslaan