Sfoglia il codice sorgente

Mails & component

master
Kobus Botha 5 anni fa
parent
commit
bc1c824ef1

+ 10
- 10
UnivateProperties_API/Controllers/Communication/TemplateController.cs Vedi File

71
             return new OkResult();
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 Vedi File

115
                 return new OkResult();
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 Vedi File

6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Model;
7
 using UnivateProperties_API.Model;
8
 using UnivateProperties_API.Model.Communication;
8
 using UnivateProperties_API.Model.Communication;
9
+using UnivateProperties_API.Model.Timeshare;
9
 using UnivateProperties_API.Model.Users;
10
 using UnivateProperties_API.Model.Users;
10
 
11
 
11
 namespace UnivateProperties_API.Repository.Communication
12
 namespace UnivateProperties_API.Repository.Communication
94
 
95
 
95
         private void CheckListChange(List<PlaceHolder> holderOld, List<PlaceHolder> holderNew)
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
                     var i = _dbContext.PlaceHolders.FirstOrDefault(x => x.Id == item.Id);
102
                     var i = _dbContext.PlaceHolders.FirstOrDefault(x => x.Id == item.Id);
102
-                    if(item != null)
103
+                    if (item != null)
103
                     {
104
                     {
104
                         _dbContext.PlaceHolders.Remove(i);
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
                 _dbContext.Add(item);
111
                 _dbContext.Add(item);
111
             }
112
             }
130
         public List<TemplateDto> GetSimpleAll()
131
         public List<TemplateDto> GetSimpleAll()
131
         {
132
         {
132
             List<TemplateDto> list = new List<TemplateDto>();
133
             List<TemplateDto> list = new List<TemplateDto>();
133
-            foreach(var item in GetAll())
134
+            foreach (var item in GetAll())
134
             {
135
             {
135
                 list.Add(new TemplateDto()
136
                 list.Add(new TemplateDto()
136
                 {
137
                 {
147
         private List<PlaceHolderDto> GetPlaceHolders(int id)
148
         private List<PlaceHolderDto> GetPlaceHolders(int id)
148
         {
149
         {
149
             List<PlaceHolderDto> list = new List<PlaceHolderDto>();
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
                 list.Add(new PlaceHolderDto()
153
                 list.Add(new PlaceHolderDto()
153
                 {
154
                 {
161
             return list;
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
                     try
195
                     try
195
                     {
196
                     {
196
-                        Email email = new Email(template, person, list);
197
+                        Email email = new Email(template, sendTo, list);
197
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
198
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
198
                         emailRepo.Insert(email);
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 Vedi File

4
 using System.Linq;
4
 using System.Linq;
5
 using UnivateProperties_API.Containers.ProcessFlow;
5
 using UnivateProperties_API.Containers.ProcessFlow;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model;
8
+using UnivateProperties_API.Model.Communication;
7
 using UnivateProperties_API.Model.ProcessFlow;
9
 using UnivateProperties_API.Model.ProcessFlow;
10
+using UnivateProperties_API.Repository.Communication;
8
 
11
 
9
 namespace UnivateProperties_API.Repository.ProccessFlow
12
 namespace UnivateProperties_API.Repository.ProccessFlow
10
 {
13
 {
41
         public List<BidItemDisplay> GetAllBid()
44
         public List<BidItemDisplay> GetAllBid()
42
         {
45
         {
43
             List<BidItem> bids = _dbContext.BidItems
46
             List<BidItem> bids = _dbContext.BidItems
44
-                .Include("Property")                
47
+                .Include("Property")
45
                 .Include("TimeshareWeek")
48
                 .Include("TimeshareWeek")
46
                 .Include("BidMaker")
49
                 .Include("BidMaker")
47
                 .Include("Status")
50
                 .Include("Status")
77
                     Comment = item.Comment,
80
                     Comment = item.Comment,
78
                     DeclineReason = item.DeclinedReason
81
                     DeclineReason = item.DeclinedReason
79
                 };
82
                 };
80
-     
83
+
81
                 if (item.PropertyId != null)
84
                 if (item.PropertyId != null)
82
                 {
85
                 {
83
                     bid.Type = "Property";
86
                     bid.Type = "Property";
114
         {
117
         {
115
             var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
118
             var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
116
             if (status != null)
119
             if (status != null)
120
+            {
121
+                List<BaseEntity> list = new List<BaseEntity>()  { item };
117
                 item.StatusId = status.Id;
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
             _dbContext.Add(item);
146
             _dbContext.Add(item);
120
             Save();
147
             Save();
121
         }
148
         }
165
         }
192
         }
166
 
193
 
167
         public BidItemDisplay AcceptBid(int id)
194
         public BidItemDisplay AcceptBid(int id)
168
-        {            
195
+        {
169
             var item = _dbContext.BidItems
196
             var item = _dbContext.BidItems
170
                 .Include("Property")
197
                 .Include("Property")
171
                 .Include("TimeshareWeek")
198
                 .Include("TimeshareWeek")
173
                 .Include("Status")
200
                 .Include("Status")
174
                 .Where(x => x.Id == id).FirstOrDefault();
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
             if (status != null)
207
             if (status != null)
181
             {
208
             {
182
-                item.StatusId = status.Id;                
209
+                item.StatusId = status.Id;
183
             }
210
             }
184
 
211
 
185
             _dbContext.Entry(item).State = EntityState.Modified;
212
             _dbContext.Entry(item).State = EntityState.Modified;
190
         }
217
         }
191
 
218
 
192
         public BidItemDisplay DecineBid(BitItemDecline item)
219
         public BidItemDisplay DecineBid(BitItemDecline item)
193
-        {            
220
+        {
194
             var bid = _dbContext.BidItems
221
             var bid = _dbContext.BidItems
195
                 .Include("Property")
222
                 .Include("Property")
196
                 .Include("TimeshareWeek")
223
                 .Include("TimeshareWeek")
199
                 .Where(x => x.Id == item.Id).FirstOrDefault();
226
                 .Where(x => x.Id == item.Id).FirstOrDefault();
200
 
227
 
201
             var status = (from s in _dbContext.Status
228
             var status = (from s in _dbContext.Status
202
-                          where s.Code == "E3"                          
229
+                          where s.Code == "E3"
203
                           select s).FirstOrDefault();
230
                           select s).FirstOrDefault();
204
 
231
 
205
             if (status != null)
232
             if (status != null)
206
             {
233
             {
207
-                bid.StatusId = status.Id;               
234
+                bid.StatusId = status.Id;
208
             }
235
             }
209
 
236
 
210
             bid.DeclinedReason = item.Comment;
237
             bid.DeclinedReason = item.Comment;

+ 26
- 1
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Vedi File

11
 using UnivateProperties_API.Containers.Users;
11
 using UnivateProperties_API.Containers.Users;
12
 using UnivateProperties_API.Context;
12
 using UnivateProperties_API.Context;
13
 using UnivateProperties_API.Helpers;
13
 using UnivateProperties_API.Helpers;
14
+using UnivateProperties_API.Model;
14
 using UnivateProperties_API.Model.Region;
15
 using UnivateProperties_API.Model.Region;
15
 using UnivateProperties_API.Model.Timeshare;
16
 using UnivateProperties_API.Model.Timeshare;
17
+using UnivateProperties_API.Repository.Communication;
16
 using UnivateProperties_API.Repository.Region;
18
 using UnivateProperties_API.Repository.Region;
17
 using UnivateProperties_API.Repository.Users;
19
 using UnivateProperties_API.Repository.Users;
18
 
20
 
317
             return _TenderId++;
319
             return _TenderId++;
318
         }
320
         }
319
 
321
 
320
-        private List<WeekDto> GetTenderWeeks()
322
+        public List<WeekDto> GetTenderWeeks()
321
         {
323
         {
322
             List<WeekDto> list = new List<WeekDto>();
324
             List<WeekDto> list = new List<WeekDto>();
323
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MyCommon.TenderUrl);
325
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MyCommon.TenderUrl);
398
             {
400
             {
399
                 week.Status = newStatus;
401
                 week.Status = newStatus;
400
                 Update(week);
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
     }

Loading…
Annulla
Salva