Browse Source

Templates

master
Kobus Botha 5 years ago
parent
commit
3a2eb3e8c7

+ 26
- 0
UnivateProperties_API/Helpers/MyCommon.cs View File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
+using System.IO;
3
 using System.Linq;
4
 using System.Linq;
5
+using System.Net;
6
+using System.Text;
4
 using System.Text.RegularExpressions;
7
 using System.Text.RegularExpressions;
5
 using UnivateProperties_API.Helpers.Attributes;
8
 using UnivateProperties_API.Helpers.Attributes;
9
+using UnivateProperties_API.Model.Timeshare;
6
 
10
 
7
 namespace UnivateProperties_API.Helpers
11
 namespace UnivateProperties_API.Helpers
8
 {
12
 {
9
     public static class MyCommon
13
     public static class MyCommon
10
     {
14
     {
15
+        public static bool PostToConsoft(TimeshareWeek week)
16
+        {
17
+            bool flag = false;
18
+            try
19
+            {
20
+                var search = $"http://www.unipoint-consoft.co.za/nph-srep.exe?cluvbank_test.sch&CLUB=LPA&TYPE=BANK&RESORT={week.ResortCode}&UNIT={week.UnitNumber}&MODULE={week.WeekNumber}&YEAR={week.ArrivalDate.Year}&BANKTO=UV";
21
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search);
22
+                request.Method = "GET";
23
+                WebResponse response = request.GetResponse();
24
+                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
25
+                {
26
+                    string result = reader.ReadToEnd();
27
+                    flag = result.ToLower().Contains("success");
28
+                }
29
+            }
30
+            catch (Exception)
31
+            {
32
+
33
+            }
34
+            return flag;
35
+        }
36
+
11
         public static List<string> GetVisibleColumns<T>(T item) where T : new()
37
         public static List<string> GetVisibleColumns<T>(T item) where T : new()
12
         {
38
         {
13
             List<string> list = new List<string>();
39
             List<string> list = new List<string>();

+ 2
- 15
UnivateProperties_API/Repository/Communication/TemplateRepository.cs View File

162
             return list;
162
             return list;
163
         }
163
         }
164
 
164
 
165
-        public void SendEmailTemplate(Template template, TimeshareWeek week, Individual owner, Person sendTo, List<BaseEntity> args)
165
+        public void SendEmailTemplate(Template template, Person sendTo, List<BaseEntity> args)
166
         {
166
         {
167
             if (template != null)
167
             if (template != null)
168
             {
168
             {
169
-                List<BaseEntity> list = new List<BaseEntity>();
170
-                if (owner != null)
171
-                {
172
-                    list.Add(owner);
173
-                }
174
-                if (week != null)
175
-                {
176
-                    list.Add(week);
177
-                }
178
-                if (args != null && args.Count > 1)
179
-                {
180
-                    list.AddRange(args);
181
-                }
182
                 if (template.SenderId == null)
169
                 if (template.SenderId == null)
183
                 {
170
                 {
184
                     var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
171
                     var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
194
                 {
181
                 {
195
                     try
182
                     try
196
                     {
183
                     {
197
-                        Email email = new Email(template, sendTo, list);
184
+                        Email email = new Email(template, sendTo, args);
198
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
185
                         EmailRepository emailRepo = new EmailRepository(_dbContext);
199
                         emailRepo.Insert(email);
186
                         emailRepo.Insert(email);
200
                     }
187
                     }

+ 31
- 20
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs View 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.Helpers;
7
 using UnivateProperties_API.Model;
8
 using UnivateProperties_API.Model;
8
 using UnivateProperties_API.Model.Communication;
9
 using UnivateProperties_API.Model.Communication;
9
 using UnivateProperties_API.Model.ProcessFlow;
10
 using UnivateProperties_API.Model.ProcessFlow;
10
 using UnivateProperties_API.Repository.Communication;
11
 using UnivateProperties_API.Repository.Communication;
12
+using UnivateProperties_API.Repository.Timeshare;
11
 
13
 
12
 namespace UnivateProperties_API.Repository.ProccessFlow
14
 namespace UnivateProperties_API.Repository.ProccessFlow
13
 {
15
 {
115
 
117
 
116
         public void Insert(BidItem item)
118
         public void Insert(BidItem item)
117
         {
119
         {
118
-            var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
119
-            if (status != null)
120
+            var week = _dbContext.Weeks.Find(item.TimeshareWeekId);
121
+            if (!(item.TimeshareWeek == null && week == null))
120
             {
122
             {
121
-                List<BaseEntity> list = new List<BaseEntity>()  { item };
122
-                item.StatusId = status.Id;
123
-                if (item.TimeshareWeekId != null)
123
+                if (week == null && item.TimeshareWeek != null)
124
                 {
124
                 {
125
-                    var week = _dbContext.Weeks.FirstOrDefault(x => x.Id == item.TimeshareWeekId);
126
-                    if (week != null)
125
+                    MyCommon.PostToConsoft(item.TimeshareWeek);
126
+                    WeekRepository weekRepository = new WeekRepository(_dbContext);
127
+                    weekRepository.Insert(item.TimeshareWeek);
128
+                }
129
+                var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
130
+                if (status != null)
131
+                {
132
+                    List<BaseEntity> list = new List<BaseEntity>() { item, week, week.Owner };
133
+                    item.StatusId = status.Id;
134
+                    if (item.TimeshareWeekId != null)
127
                     {
135
                     {
128
-                        TemplateRepository templateRepository = new TemplateRepository(_dbContext);
129
-                        var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-Owner");
130
-                        if (template != null)
136
+                        if (week != null)
131
                         {
137
                         {
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)
138
+                            TemplateRepository templateRepository = new TemplateRepository(_dbContext);
139
+                            var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-Owner");
140
+                            if (template != null)
141
+                            {
142
+                                templateRepository.SendEmailTemplate(template, week.Owner, list);
143
+                            }
144
+                            template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-User");
145
+                            if (template != null)
139
                             {
146
                             {
140
-                                templateRepository.SendEmailTemplate(template, week, week.Owner, bidMaker, list);
147
+                                var bidMaker = _dbContext.Individuals.FirstOrDefault(x => x.Id == item.BidMakerId);
148
+                                if (bidMaker != null)
149
+                                {
150
+                                    templateRepository.SendEmailTemplate(template, bidMaker, list);
151
+                                }
141
                             }
152
                             }
142
                         }
153
                         }
143
                     }
154
                     }
144
                 }
155
                 }
156
+                _dbContext.Add(item);
157
+                Save();
145
             }
158
             }
146
-            _dbContext.Add(item);
147
-            Save();
148
         }
159
         }
149
 
160
 
150
         public void Insert(IEnumerable<BidItem> items)
161
         public void Insert(IEnumerable<BidItem> items)

+ 23
- 19
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs View File

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;
15
+using UnivateProperties_API.Model.Communication;
15
 using UnivateProperties_API.Model.Region;
16
 using UnivateProperties_API.Model.Region;
16
 using UnivateProperties_API.Model.Timeshare;
17
 using UnivateProperties_API.Model.Timeshare;
17
 using UnivateProperties_API.Repository.Communication;
18
 using UnivateProperties_API.Repository.Communication;
197
         public void Insert(TimeshareWeek item)
198
         public void Insert(TimeshareWeek item)
198
         {
199
         {
199
             item = GetDetailedWeek(item);
200
             item = GetDetailedWeek(item);
200
-            item.Id = _dbContext.Weeks.Max(x => x.Id) + 1;
201
-            if (item.Owner != null && item.Owner.Id == 0)
202
-            {
203
-                item.Owner.Id = _dbContext.Individuals.Max(x => x.Id) + 1;
204
-            }
205
-            // Set starting Status of A1
206
             StatusRepository repo = new StatusRepository(_dbContext);
201
             StatusRepository repo = new StatusRepository(_dbContext);
207
-            item.Status = repo.GetDetailed(s => s.Code == "A1");
208
-            if (item.Status != null)
202
+            var stat = repo.Get(x => x.Code == "A1" && x.StatusType == StatusType.Timeshare).FirstOrDefault();
203
+            if (stat == null)
209
             {
204
             {
210
                 //Create initial
205
                 //Create initial
211
-                item.Status = new Status()
206
+                stat = new Status()
212
                 {
207
                 {
213
                     Code = "A1",
208
                     Code = "A1",
214
                     Description = "Pending verification",
209
                     Description = "Pending verification",
215
                     StatusType = StatusType.Timeshare,
210
                     StatusType = StatusType.Timeshare,
216
                     ModifiedBy = "KobusB"
211
                     ModifiedBy = "KobusB"
217
                 };
212
                 };
213
+                repo.Insert(stat);
218
             }
214
             }
219
             item.Id = NewId();
215
             item.Id = NewId();
220
-            UnivateProperties_API.Model.ProcessFlow.ProcessFlow flowItem = new Model.ProcessFlow.ProcessFlow()
216
+            item.ProcessFlows.Add(new Model.ProcessFlow.ProcessFlow()
221
             {
217
             {
222
                 Status = item.Status,
218
                 Status = item.Status,
223
                 Timeshare = item
219
                 Timeshare = item
224
-            };
220
+            });
221
+            TemplateRepository templateRepository = new TemplateRepository(_dbContext);
222
+            if(item.Owner != null)
223
+            {
224
+                var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Owner");
225
+                if(template != null)
226
+                {
227
+                    templateRepository.SendEmailTemplate(template, item.Owner, new List<BaseEntity>() { item, item.Owner });
228
+                }
229
+                template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-UV");
230
+                if(template != null)
231
+                {
232
+                    templateRepository.SendEmailTemplate(template, item.Owner, new List<BaseEntity>() { item, item.Owner });
233
+                }
234
+            }            
225
             _dbContext.Add(item);
235
             _dbContext.Add(item);
226
-            _dbContext.Add(flowItem);
227
             Save();
236
             Save();
228
         }
237
         }
229
 
238
 
403
                 var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
412
                 var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
404
                 if(template != null)
413
                 if(template != null)
405
                 {
414
                 {
415
+                    
406
                     TemplateRepository tempRepo = new TemplateRepository(_dbContext);
416
                     TemplateRepository tempRepo = new TemplateRepository(_dbContext);
407
-                    tempRepo.SendEmailTemplate(template, week, week.Owner, week.Owner, new List<BaseEntity>());
417
+                    tempRepo.SendEmailTemplate(template, week.Owner, new List<BaseEntity>() { week, week.Owner});
408
                 }
418
                 }
409
             }
419
             }
410
         }
420
         }
417
             {
427
             {
418
                 week.Status = newStatus;
428
                 week.Status = newStatus;
419
                 Update(week);
429
                 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
-                }
426
             }
430
             }
427
         }
431
         }
428
     }
432
     }

Loading…
Cancel
Save