ソースを参照

Mails & component

master
Kobus Botha 5年前
コミット
bc1c824ef1

+ 10
- 10
UnivateProperties_API/Controllers/Communication/TemplateController.cs ファイルの表示

@@ -71,15 +71,15 @@ namespace UnivateProperties_API.Controllers.Communication
71 71
             return new OkResult();
72 72
         }
73 73
 
74
-        [HttpPost("sendTemplate/{id}")]
75
-        public IActionResult SendTemplate(int id)
76
-        {
77
-            using ( var scope = new TransactionScope())
78
-            {
79
-                (_Repo as TemplateRepository).SendEmailTemplate(id);
80
-                scope.Complete();
81
-                return new OkResult();
82
-            }
83
-        }
74
+        //[HttpPost("sendTemplate/{id}")]
75
+        //public IActionResult SendTemplate(int id)
76
+        //{
77
+        //    using ( var scope = new TransactionScope())
78
+        //    {
79
+        //        (_Repo as TemplateRepository).SendEmailTemplate(id);
80
+        //        scope.Complete();
81
+        //        return new OkResult();
82
+        //    }
83
+        //}
84 84
     }
85 85
 }

+ 18
- 0
UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs ファイルの表示

@@ -115,5 +115,23 @@ namespace UnivateProperties_API.Controllers.Timeshare
115 115
                 return new OkResult();
116 116
             }
117 117
         }
118
+
119
+        [HttpPost("publishweek/{id}")]
120
+        public IActionResult Publishweek(int id)
121
+        {
122
+            using (var scope = new TransactionScope())
123
+            {
124
+                (_Repo as WeekRepository).VerifyWeek(id);
125
+                scope.Complete();
126
+                return new OkResult();
127
+            }
128
+        }
129
+
130
+        [HttpGet("getTenderWeeks")]
131
+        public IActionResult GetTenderWeeks()
132
+        {
133
+            var item = (_Repo as WeekRepository).GetTenderWeeks();
134
+            return new OkObjectResult(item);
135
+        }
118 136
     }
119 137
 }

+ 34
- 33
UnivateProperties_API/Repository/Communication/TemplateRepository.cs ファイルの表示

@@ -6,6 +6,7 @@ using UnivateProperties_API.Containers.Communication;
6 6
 using UnivateProperties_API.Context;
7 7
 using UnivateProperties_API.Model;
8 8
 using UnivateProperties_API.Model.Communication;
9
+using UnivateProperties_API.Model.Timeshare;
9 10
 using UnivateProperties_API.Model.Users;
10 11
 
11 12
 namespace UnivateProperties_API.Repository.Communication
@@ -94,18 +95,18 @@ namespace UnivateProperties_API.Repository.Communication
94 95
 
95 96
         private void CheckListChange(List<PlaceHolder> holderOld, List<PlaceHolder> holderNew)
96 97
         {
97
-            foreach(var item in holderOld)
98
+            foreach (var item in holderOld)
98 99
             {
99
-                if(!holderNew.Any(x => x.Id== item.Id))
100
+                if (!holderNew.Any(x => x.Id == item.Id))
100 101
                 {
101 102
                     var i = _dbContext.PlaceHolders.FirstOrDefault(x => x.Id == item.Id);
102
-                    if(item != null)
103
+                    if (item != null)
103 104
                     {
104 105
                         _dbContext.PlaceHolders.Remove(i);
105 106
                     }
106 107
                 }
107 108
             }
108
-            foreach(var item in holderNew.Where(x => x.Id == 0))
109
+            foreach (var item in holderNew.Where(x => x.Id == 0))
109 110
             {
110 111
                 _dbContext.Add(item);
111 112
             }
@@ -130,7 +131,7 @@ namespace UnivateProperties_API.Repository.Communication
130 131
         public List<TemplateDto> GetSimpleAll()
131 132
         {
132 133
             List<TemplateDto> list = new List<TemplateDto>();
133
-            foreach(var item in GetAll())
134
+            foreach (var item in GetAll())
134 135
             {
135 136
                 list.Add(new TemplateDto()
136 137
                 {
@@ -147,7 +148,7 @@ namespace UnivateProperties_API.Repository.Communication
147 148
         private List<PlaceHolderDto> GetPlaceHolders(int id)
148 149
         {
149 150
             List<PlaceHolderDto> list = new List<PlaceHolderDto>();
150
-            foreach(var item in _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList())
151
+            foreach (var item in _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList())
151 152
             {
152 153
                 list.Add(new PlaceHolderDto()
153 154
                 {
@@ -161,46 +162,46 @@ namespace UnivateProperties_API.Repository.Communication
161 162
             return list;
162 163
         }
163 164
 
164
-        public void SendEmailTemplate(int id)
165
+        public void SendEmailTemplate(Template template, TimeshareWeek week, Individual owner, Person sendTo, List<BaseEntity> args)
165 166
         {
166
-            var item = _dbContext.Weeks.FirstOrDefault(x => x.Id == 4);
167
-            var indiv = _dbContext.Individuals.FirstOrDefault(x => x.Id == 73);
168
-            List<BaseEntity> list = new List<BaseEntity>
167
+            if (template != null)
169 168
             {
170
-                item,
171
-                indiv
172
-            };
173
-            var template = _dbContext.Templates.FirstOrDefault(x => x.Id == id);
174
-            if (template.SenderId == null)
175
-            {
176
-                var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
177
-                if (acc != null)
169
+                List<BaseEntity> list = new List<BaseEntity>();
170
+                if (owner != null)
178 171
                 {
179
-                    template.SenderId = acc.Id;
180
-                    template.Sender = acc;
172
+                    list.Add(owner);
181 173
                 }
182
-            }
183
-            else template.Sender = _dbContext.Accounts.FirstOrDefault(x => x.Id == template.SenderId);
184
-            template.PlaceHolders = _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList();
185
-            if(template != null)
186
-            {
187
-                Person person = _dbContext.Individuals.FirstOrDefault(x => x.Email == "kobusb@provision-sa.com");
188
-                if(person == null)
174
+                if (week != null)
189 175
                 {
190
-                    person = _dbContext.Agents.FirstOrDefault(x => x.Email == "kobusb@provision-sa.com");
176
+                    list.Add(week);
191 177
                 }
192
-                if(person != null)
178
+                if (args != null && args.Count > 1)
179
+                {
180
+                    list.AddRange(args);
181
+                }
182
+                if (template.SenderId == null)
183
+                {
184
+                    var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
185
+                    if (acc != null)
186
+                    {
187
+                        template.SenderId = acc.Id;
188
+                        template.Sender = acc;
189
+                    }
190
+                }
191
+                else template.Sender = _dbContext.Accounts.FirstOrDefault(x => x.Id == template.SenderId);
192
+                template.PlaceHolders = _dbContext.PlaceHolders.Where(x => x.TemplateId == template.Id).ToList();
193
+                if (sendTo != null)
193 194
                 {
194 195
                     try
195 196
                     {
196
-                        Email email = new Email(template, person, list);
197
+                        Email email = new Email(template, sendTo, list);
197 198
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
198 199
                         emailRepo.Insert(email);
199 200
                     }
200
-                    catch(Exception)
201
+                    catch (Exception)
201 202
                     {
202
-                    }                    
203
-                }                
203
+                    }
204
+                }
204 205
             }
205 206
         }
206 207
     }

+ 38
- 11
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs ファイルの表示

@@ -4,7 +4,10 @@ using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Containers.ProcessFlow;
6 6
 using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model;
8
+using UnivateProperties_API.Model.Communication;
7 9
 using UnivateProperties_API.Model.ProcessFlow;
10
+using UnivateProperties_API.Repository.Communication;
8 11
 
9 12
 namespace UnivateProperties_API.Repository.ProccessFlow
10 13
 {
@@ -41,7 +44,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
41 44
         public List<BidItemDisplay> GetAllBid()
42 45
         {
43 46
             List<BidItem> bids = _dbContext.BidItems
44
-                .Include("Property")                
47
+                .Include("Property")
45 48
                 .Include("TimeshareWeek")
46 49
                 .Include("BidMaker")
47 50
                 .Include("Status")
@@ -77,7 +80,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
77 80
                     Comment = item.Comment,
78 81
                     DeclineReason = item.DeclinedReason
79 82
                 };
80
-     
83
+
81 84
                 if (item.PropertyId != null)
82 85
                 {
83 86
                     bid.Type = "Property";
@@ -114,8 +117,32 @@ namespace UnivateProperties_API.Repository.ProccessFlow
114 117
         {
115 118
             var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
116 119
             if (status != null)
120
+            {
121
+                List<BaseEntity> list = new List<BaseEntity>()  { item };
117 122
                 item.StatusId = status.Id;
118
-
123
+                if (item.TimeshareWeekId != null)
124
+                {
125
+                    var week = _dbContext.Weeks.FirstOrDefault(x => x.Id == item.TimeshareWeekId);
126
+                    if (week != null)
127
+                    {
128
+                        TemplateRepository templateRepository = new TemplateRepository(_dbContext);
129
+                        var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-Owner");
130
+                        if (template != null)
131
+                        {
132
+                            templateRepository.SendEmailTemplate(template, week, week.Owner, week.Owner, list);
133
+                        }
134
+                        template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-User");
135
+                        if (template != null)
136
+                        {
137
+                            var bidMaker = _dbContext.Individuals.FirstOrDefault(x => x.Id == item.BidMakerId);
138
+                            if(bidMaker != null)
139
+                            {
140
+                                templateRepository.SendEmailTemplate(template, week, week.Owner, bidMaker, list);
141
+                            }
142
+                        }
143
+                    }
144
+                }
145
+            }
119 146
             _dbContext.Add(item);
120 147
             Save();
121 148
         }
@@ -165,7 +192,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
165 192
         }
166 193
 
167 194
         public BidItemDisplay AcceptBid(int id)
168
-        {            
195
+        {
169 196
             var item = _dbContext.BidItems
170 197
                 .Include("Property")
171 198
                 .Include("TimeshareWeek")
@@ -173,13 +200,13 @@ namespace UnivateProperties_API.Repository.ProccessFlow
173 200
                 .Include("Status")
174 201
                 .Where(x => x.Id == id).FirstOrDefault();
175 202
 
176
-            var status =  (from s in _dbContext.Status
177
-                           where s.Code == "E2"                           
178
-                           select s).FirstOrDefault();
203
+            var status = (from s in _dbContext.Status
204
+                          where s.Code == "E2"
205
+                          select s).FirstOrDefault();
179 206
 
180 207
             if (status != null)
181 208
             {
182
-                item.StatusId = status.Id;                
209
+                item.StatusId = status.Id;
183 210
             }
184 211
 
185 212
             _dbContext.Entry(item).State = EntityState.Modified;
@@ -190,7 +217,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
190 217
         }
191 218
 
192 219
         public BidItemDisplay DecineBid(BitItemDecline item)
193
-        {            
220
+        {
194 221
             var bid = _dbContext.BidItems
195 222
                 .Include("Property")
196 223
                 .Include("TimeshareWeek")
@@ -199,12 +226,12 @@ namespace UnivateProperties_API.Repository.ProccessFlow
199 226
                 .Where(x => x.Id == item.Id).FirstOrDefault();
200 227
 
201 228
             var status = (from s in _dbContext.Status
202
-                          where s.Code == "E3"                          
229
+                          where s.Code == "E3"
203 230
                           select s).FirstOrDefault();
204 231
 
205 232
             if (status != null)
206 233
             {
207
-                bid.StatusId = status.Id;               
234
+                bid.StatusId = status.Id;
208 235
             }
209 236
 
210 237
             bid.DeclinedReason = item.Comment;

+ 26
- 1
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs ファイルの表示

@@ -11,8 +11,10 @@ using UnivateProperties_API.Containers.Timeshare.Detailed;
11 11
 using UnivateProperties_API.Containers.Users;
12 12
 using UnivateProperties_API.Context;
13 13
 using UnivateProperties_API.Helpers;
14
+using UnivateProperties_API.Model;
14 15
 using UnivateProperties_API.Model.Region;
15 16
 using UnivateProperties_API.Model.Timeshare;
17
+using UnivateProperties_API.Repository.Communication;
16 18
 using UnivateProperties_API.Repository.Region;
17 19
 using UnivateProperties_API.Repository.Users;
18 20
 
@@ -317,7 +319,7 @@ namespace UnivateProperties_API.Repository.Timeshare
317 319
             return _TenderId++;
318 320
         }
319 321
 
320
-        private List<WeekDto> GetTenderWeeks()
322
+        public List<WeekDto> GetTenderWeeks()
321 323
         {
322 324
             List<WeekDto> list = new List<WeekDto>();
323 325
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MyCommon.TenderUrl);
@@ -398,6 +400,29 @@ namespace UnivateProperties_API.Repository.Timeshare
398 400
             {
399 401
                 week.Status = newStatus;
400 402
                 Update(week);
403
+                var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
404
+                if(template != null)
405
+                {
406
+                    TemplateRepository tempRepo = new TemplateRepository(_dbContext);
407
+                    tempRepo.SendEmailTemplate(template, week, week.Owner, week.Owner, new List<BaseEntity>());
408
+                }
409
+            }
410
+        }
411
+
412
+        public void PublishWeek(int id)
413
+        {
414
+            var week = _dbContext.Weeks.FirstOrDefault(x => x.Id == id);
415
+            var newStatus = _dbContext.Status.FirstOrDefault(x => x.Code.ToLower() == "b1" && x.StatusType == StatusType.Timeshare);
416
+            if (week != null && newStatus != null)
417
+            {
418
+                week.Status = newStatus;
419
+                Update(week);
420
+                var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
421
+                if (template != null)
422
+                {
423
+                    TemplateRepository tempRepo = new TemplateRepository(_dbContext);
424
+                    tempRepo.SendEmailTemplate(template, week, week.Owner, week.Owner, new List<BaseEntity>());
425
+                }
401 426
             }
402 427
         }
403 428
     }

読み込み中…
キャンセル
保存