瀏覽代碼

MailService Update

master
30117125 4 年之前
父節點
當前提交
1cf05571f0

+ 6
- 0
UnivateProperties_API/Controllers/Timeshare/ResortController.cs 查看文件

43
         {
43
         {
44
             return new OkObjectResult(_Repo.GetResortData(code));
44
             return new OkObjectResult(_Repo.GetResortData(code));
45
         }
45
         }
46
+
47
+        [HttpGet("GetPublishedResortsWithListings")]
48
+        public IActionResult GetResortsWithListings()
49
+        {
50
+            return new OkObjectResult(_Repo.GetResortsWithListings());
51
+        }
46
     }
52
     }
47
 }
53
 }

+ 32
- 5
UnivateProperties_API/Repository/Communication/MailRepository.cs 查看文件

6
 using System.Linq.Dynamic.Core;
6
 using System.Linq.Dynamic.Core;
7
 using System.Net.Mail;
7
 using System.Net.Mail;
8
 using System.Text;
8
 using System.Text;
9
+using UnivateProperties_API.Containers.Timeshare;
9
 using UnivateProperties_API.Context;
10
 using UnivateProperties_API.Context;
10
 using UnivateProperties_API.Helpers;
11
 using UnivateProperties_API.Helpers;
11
 using UnivateProperties_API.Model.Communication;
12
 using UnivateProperties_API.Model.Communication;
314
             }
315
             }
315
         }
316
         }
316
 
317
 
317
-        public void WeekLoadedOwner(TimeshareWeek week)
318
+        public void WeekLoadedOwner(TimeshareWeekDto week)
318
         {
319
         {
319
             string body = _dbContext.Templates.Where(x => x.Name == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
320
             string body = _dbContext.Templates.Where(x => x.Name == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
320
             var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).ToList();
321
             var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).ToList();
321
 
322
 
322
-            body = body.Replace("[FULLNAME]", week.DisplayOwner);
323
-            body = body.Replace("[RESORTNAME]", week.ResortName);
324
-            body = body.Replace("[UNITNUMBER]", week.UnitNumber);
325
-            body = body.Replace("[MODULE]", week.Module);
323
+            #region ResortFields
324
+            body = body.Replace("[RESORTNAME]", " " + week.ResortName);
325
+            body = body.Replace("[UNITNUMBER]", " " + week.UnitNumber);
326
+            body = body.Replace("[MODULE]", " " + week.Module);
327
+            body = body.Replace("[RESORTPRICE]", " " + week.SellPrice.ToString());
328
+            body = body.Replace("[RESORTSEASON]", " " + week.Season);
329
+            body = body.Replace("[RESORTREGION]", " " + week.Region.Display);
330
+            body = body.Replace("[RESORTLEVY]", " " + week.LevyAmount.ToString());           
331
+            body = body.Replace("[OWNER]", " " + week.DisplayOwner);
332
+            body = body.Replace("[SLEEPMAX]", " " + week.MaxSleep.ToString());
333
+            body = body.Replace("[WEEK]", " " + week.WeekNumber);
334
+            body = body.Replace("[BEDROOMS]", " " + week.Bedrooms);
335
+            body = body.Replace("[ASKINGPRICE]", " " + week.AskingPrice.ToString());
336
+            body = body.Replace("[ARRIVALDATE]", " " + week.ArrivalDate.ToString());
337
+            body = body.Replace("[DEPARTUREDATE]", " " + week.DepartureDate.ToString());
338
+            body = body.Replace("[AGENTREFER]", week.ReferedByAgent ? " Yes" : " No");
339
+            body = body.Replace("[ALLLEVY]", week.LeviesPaidInFull ? " Yes" : " No");
340
+            body = body.Replace("[WEEKPLACEDFORRENTAL]", week.WeekPlacedForRental ? " Yes" : " No");
341
+            body = body.Replace("[ORIGINALPURCHASEDATE]", " " + week.OriginalPurchaseDate.ToString());
342
+            body = body.Replace("[CUROCCUPATIONDATES]", " " + week.ArrivalDate.ToString() + " - " + week.DepartureDate.ToString());
343
+            body = body.Replace("[ORIGINALPURCHASEPRICE]", " " + week.OriginalPurchasePrice.ToString());
344
+            body = body.Replace("[AGENTCOMM]", " " + week.AgentCommision.ToString());
345
+            #endregion
346
+
347
+            #region UserFields
348
+            body = body.Replace("[FULLNAME]", " " + week.DisplayOwner );
349
+            body = body.Replace("[USEREMAIL]", " " + week.OwnerObject.EmailAddress);
350
+            body = body.Replace("[USERCELLPHONE]", " " + week.OwnerObject.CellNumber);
351
+            body = body.Replace("[USERTELEPHONE]", " " + week.OwnerObject.LandlineNumber);
352
+            #endregion
326
 
353
 
327
             string toList = "";
354
             string toList = "";
328
             int emailCount = 0;
355
             int emailCount = 0;

+ 23
- 0
UnivateProperties_API/Repository/Timeshare/IResortRepository.cs 查看文件

2
 using RestSharp;
2
 using RestSharp;
3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Data;
4
 using System.Data;
5
+using System.Dynamic;
5
 using System.IO;
6
 using System.IO;
6
 using System.Linq;
7
 using System.Linq;
7
 using UnivateProperties_API.Containers.Timeshare;
8
 using UnivateProperties_API.Containers.Timeshare;
16
         string GetResortDescription(string resortCode);
17
         string GetResortDescription(string resortCode);
17
         List<string> GetResortImages(string resortCode);
18
         List<string> GetResortImages(string resortCode);
18
         ResortData GetResortData(string resortCode);
19
         ResortData GetResortData(string resortCode);
20
+        List<dynamic> GetResortsWithListings();
19
     }
21
     }
20
 
22
 
21
     public class ResortRepository : IResortRepository
23
     public class ResortRepository : IResortRepository
93
             return images;
95
             return images;
94
         }
96
         }
95
 
97
 
98
+        public List<dynamic> GetResortsWithListings()
99
+        {
100
+            var weeks = _dbContext.Weeks.Where(x => x.Publish).ToList();
101
+            var provinces = _dbContext.Provinces.ToList();
102
+            List<string> resortNames = new List<string>();
103
+            List<dynamic> resortObjects = new List<dynamic>();
104
+            foreach (var week in weeks)
105
+            {
106
+                dynamic resortObject = new ExpandoObject();
107
+                if (!resortNames.Contains(week.ResortName))
108
+                {
109
+                    resortNames.Add(week.ResortName);
110
+                    resortObject.resortName = week.ResortName;
111
+                    resortObject.resortCode = week.ResortCode;
112
+                    resortObject.resortRegion = provinces.Where(p => p.Id == week.RegionId);
113
+                    resortObjects.Add(resortObject);
114
+                }
115
+            }            
116
+            return resortObjects;
117
+        }
118
+
96
         public DataSet CreateDataSet(string data)
119
         public DataSet CreateDataSet(string data)
97
         {
120
         {
98
             try
121
             try

+ 42
- 22
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs 查看文件

185
             List<WeekDto> list = new List<WeekDto>();
185
             List<WeekDto> list = new List<WeekDto>();
186
             UserRepository userRepository = new UserRepository(_dbContext);
186
             UserRepository userRepository = new UserRepository(_dbContext);
187
             var user = userRepository.Get(x => x.Id == userId).FirstOrDefault();
187
             var user = userRepository.Get(x => x.Id == userId).FirstOrDefault();
188
-            if (user.IsUserInRole(Role.SuperAdmin))
188
+            if (userId == 0)
189
             {
189
             {
190
                 foreach (var item in GetDetailedAll())
190
                 foreach (var item in GetDetailedAll())
191
                 {
191
                 {
192
-                    list.Add(new WeekDto(item));
192
+                    if (item.Publish)
193
+                    {
194
+                        list.Add(new WeekDto(item));
195
+                    }
196
+
193
                 }
197
                 }
194
             }
198
             }
195
-            else if (user.IsUserInRole(Role.Agency))
199
+            else 
196
             {
200
             {
197
-                var agent = _dbContext.Agents.FirstOrDefault(x => x.UserId == userId);
198
-                if(agent != null)
201
+                if (user.IsUserInRole(Role.SuperAdmin))
199
                 {
202
                 {
200
-                    foreach (var item in GetDetailedAll().Where(x => x.AgencyId == agent.AgencyId))
203
+                    foreach (var item in GetDetailedAll())
201
                     {
204
                     {
202
                         list.Add(new WeekDto(item));
205
                         list.Add(new WeekDto(item));
203
                     }
206
                     }
204
-                }                
205
-            }
206
-            else if (user.IsUserInRole(Role.Agent) || user.IsUserInRole(Role.ManagingAgent))
207
-            {
208
-                var agent = _dbContext.Agents.FirstOrDefault(x => x.UserId == userId);
209
-                if(agent != null)
207
+                }
208
+                else if (user.IsUserInRole(Role.Agency))
210
                 {
209
                 {
211
-                    foreach (var item in GetDetailedAll().Where(x => x.AgentId == agent.Id))
210
+                    var agent = _dbContext.Agents.FirstOrDefault(x => x.UserId == userId);
211
+                    if (agent != null)
212
                     {
212
                     {
213
-                        list.Add(new WeekDto(item));
213
+                        foreach (var item in GetDetailedAll().Where(x => x.AgencyId == agent.AgencyId))
214
+                        {
215
+                            list.Add(new WeekDto(item));
216
+                        }
214
                     }
217
                     }
215
                 }
218
                 }
216
-            }
217
-            else
218
-            {
219
-                var individual = _dbContext.Individuals.FirstOrDefault(x => x.UserId == userId);
220
-                if(individual != null)
219
+                else if (user.IsUserInRole(Role.Agent) || user.IsUserInRole(Role.ManagingAgent))
221
                 {
220
                 {
222
-                    foreach (var item in GetDetailedAll().Where(x => x.OwnerId == individual.Id))
221
+                    var agent = _dbContext.Agents.FirstOrDefault(x => x.UserId == userId);
222
+                    if (agent != null)
223
                     {
223
                     {
224
-                        list.Add(new WeekDto(item));
224
+                        foreach (var item in GetDetailedAll().Where(x => x.AgentId == agent.Id))
225
+                        {
226
+                            list.Add(new WeekDto(item));
227
+                        }
225
                     }
228
                     }
226
-                }                
229
+                }
230
+                else
231
+                {
232
+                    var individual = _dbContext.Individuals.FirstOrDefault(x => x.UserId == userId);
233
+                    if (individual != null)
234
+                    {
235
+                        foreach (var item in GetDetailedAll().Where(x => x.OwnerId == individual.Id))
236
+                        {
237
+                            list.Add(new WeekDto(item));
238
+                        }
239
+                    }
240
+                }
227
             }
241
             }
242
+
243
+            
228
             return list;
244
             return list;
229
         }
245
         }
230
 
246
 
420
             {
436
             {
421
                 saved.ResortCode = item.ResortCode;
437
                 saved.ResortCode = item.ResortCode;
422
             }
438
             }
439
+            if (saved.ResortName != item.ResortName)
440
+            {
441
+                saved.ResortName = item.ResortName;
442
+            }
423
             if (saved.UnitNumber != item.UnitNumber)
443
             if (saved.UnitNumber != item.UnitNumber)
424
             {
444
             {
425
                 saved.UnitNumber = item.UnitNumber;
445
                 saved.UnitNumber = item.UnitNumber;

Loading…
取消
儲存