|
@@ -1,10 +1,16 @@
|
1
|
1
|
using Microsoft.EntityFrameworkCore;
|
2
|
2
|
using System;
|
3
|
3
|
using System.Collections.Generic;
|
|
4
|
+using System.Configuration;
|
|
5
|
+using System.IO;
|
4
|
6
|
using System.Linq;
|
|
7
|
+using System.Net;
|
|
8
|
+using System.Text;
|
5
|
9
|
using UnivateProperties_API.Containers.Timeshare;
|
6
|
10
|
using UnivateProperties_API.Containers.Users;
|
7
|
11
|
using UnivateProperties_API.Context;
|
|
12
|
+using UnivateProperties_API.Helpers;
|
|
13
|
+using UnivateProperties_API.Model.Region;
|
8
|
14
|
using UnivateProperties_API.Model.Timeshare;
|
9
|
15
|
using UnivateProperties_API.Repository.Region;
|
10
|
16
|
using UnivateProperties_API.Repository.Users;
|
|
@@ -40,10 +46,14 @@ namespace UnivateProperties_API.Repository.Timeshare
|
40
|
46
|
public List<WeekDto> GetDtoListAll()
|
41
|
47
|
{
|
42
|
48
|
List<WeekDto> list = new List<WeekDto>();
|
43
|
|
- foreach(var item in GetDetailedAll())
|
|
49
|
+ foreach (var item in GetDetailedAll())
|
44
|
50
|
{
|
45
|
51
|
list.Add(new WeekDto(item));
|
46
|
52
|
}
|
|
53
|
+ foreach (var item in GetTenderWeeks())
|
|
54
|
+ {
|
|
55
|
+ list.Add(item);
|
|
56
|
+ }
|
47
|
57
|
return list;
|
48
|
58
|
}
|
49
|
59
|
|
|
@@ -52,14 +62,14 @@ namespace UnivateProperties_API.Repository.Timeshare
|
52
|
62
|
List<WeekDto> list = new List<WeekDto>();
|
53
|
63
|
UserRepository userRepository = new UserRepository(_dbContext);
|
54
|
64
|
var user = userRepository.Get(x => x.Id == userId).FirstOrDefault();
|
55
|
|
- if(user.IsUserInRole(Role.SuperAdmin))
|
|
65
|
+ if (user.IsUserInRole(Role.SuperAdmin))
|
56
|
66
|
{
|
57
|
67
|
foreach (var item in GetDetailedAll())
|
58
|
68
|
{
|
59
|
69
|
list.Add(new WeekDto(item));
|
60
|
70
|
}
|
61
|
71
|
}
|
62
|
|
- else if(user.IsUserInRole(Role.Agency))
|
|
72
|
+ else if (user.IsUserInRole(Role.Agency))
|
63
|
73
|
{
|
64
|
74
|
foreach (var item in GetDetailedAll().Where(x => x.AgencyId == userId))
|
65
|
75
|
{
|
|
@@ -102,10 +112,10 @@ namespace UnivateProperties_API.Repository.Timeshare
|
102
|
112
|
}
|
103
|
113
|
}
|
104
|
114
|
list = list.OrderBy(x => x.RegionName).ToList();
|
105
|
|
- foreach(var region in list)
|
|
115
|
+ foreach (var region in list)
|
106
|
116
|
{
|
107
|
117
|
region.OrderResorts();
|
108
|
|
- foreach(var resort in region.Resorts)
|
|
118
|
+ foreach (var resort in region.Resorts)
|
109
|
119
|
{
|
110
|
120
|
resort.Available = allItems.Count(x => x.ResortCode == resort.ResortCode);
|
111
|
121
|
}
|
|
@@ -117,7 +127,7 @@ namespace UnivateProperties_API.Repository.Timeshare
|
117
|
127
|
{
|
118
|
128
|
var list = GetAll();
|
119
|
129
|
List<TimeshareWeek> weeklist = new List<TimeshareWeek>();
|
120
|
|
- foreach(var item in list)
|
|
130
|
+ foreach (var item in list)
|
121
|
131
|
{
|
122
|
132
|
weeklist.Add(GetDetailedWeek(item));
|
123
|
133
|
}
|
|
@@ -126,12 +136,12 @@ namespace UnivateProperties_API.Repository.Timeshare
|
126
|
136
|
|
127
|
137
|
private TimeshareWeek GetDetailedWeek(TimeshareWeek week)
|
128
|
138
|
{
|
129
|
|
- if(week.AgencyId != null)
|
|
139
|
+ if (week.AgencyId != null)
|
130
|
140
|
{
|
131
|
141
|
AgencyRepository agency = new AgencyRepository(_dbContext);
|
132
|
142
|
week.Agency = agency.Get(x => x.Id == week.AgencyId).FirstOrDefault();
|
133
|
143
|
}
|
134
|
|
- if(week.AgentId != null)
|
|
144
|
+ if (week.AgentId != null)
|
135
|
145
|
{
|
136
|
146
|
AgentRepository agent = new AgentRepository(_dbContext);
|
137
|
147
|
week.Agent = agent.Get(x => x.Id == week.AgentId).FirstOrDefault();
|
|
@@ -170,7 +180,7 @@ namespace UnivateProperties_API.Repository.Timeshare
|
170
|
180
|
// Set starting Status of A1
|
171
|
181
|
StatusRepository repo = new StatusRepository(_dbContext);
|
172
|
182
|
item.Status = repo.GetDetailed(s => s.Code == "A1");
|
173
|
|
- if(item.Status != null)
|
|
183
|
+ if (item.Status != null)
|
174
|
184
|
{
|
175
|
185
|
//Create initial
|
176
|
186
|
item.Status = new Status()
|
|
@@ -224,7 +234,7 @@ namespace UnivateProperties_API.Repository.Timeshare
|
224
|
234
|
|
225
|
235
|
public void Save()
|
226
|
236
|
{
|
227
|
|
- _dbContext.SaveChanges();
|
|
237
|
+ _dbContext.SaveChanges();
|
228
|
238
|
}
|
229
|
239
|
|
230
|
240
|
public void Update(TimeshareWeek item)
|
|
@@ -271,5 +281,59 @@ namespace UnivateProperties_API.Repository.Timeshare
|
271
|
281
|
id += 1;
|
272
|
282
|
return id;
|
273
|
283
|
}
|
|
284
|
+
|
|
285
|
+ private List<WeekDto> GetTenderWeeks()
|
|
286
|
+ {
|
|
287
|
+ List<WeekDto> list = new List<WeekDto>();
|
|
288
|
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MyCommon.TenderUrl);
|
|
289
|
+ request.Method = "GET";
|
|
290
|
+ WebResponse response = request.GetResponse();
|
|
291
|
+ using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
|
|
292
|
+ {
|
|
293
|
+ string result = reader.ReadToEnd();
|
|
294
|
+
|
|
295
|
+ if (result.Length > 0)
|
|
296
|
+ {
|
|
297
|
+ string cleanLine;
|
|
298
|
+ string[] lines = result.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
|
299
|
+ foreach (string line in lines)
|
|
300
|
+ {
|
|
301
|
+ cleanLine = line.Replace("<br>", "");
|
|
302
|
+ cleanLine = line.Replace("<br/>", "");
|
|
303
|
+ list.Add(new WeekDto(cleanLine));
|
|
304
|
+ }
|
|
305
|
+ }
|
|
306
|
+ }
|
|
307
|
+ // Check that all regions are same as other
|
|
308
|
+ list
|
|
309
|
+ .Where(x => x.Region != null && x.Region.RegionCode == "FN")
|
|
310
|
+ .ToList()
|
|
311
|
+ .ForEach(x => x.Region.RegionCode = ChangeRegion(x.Region.RegionCode));
|
|
312
|
+ list = GetRegion(list);
|
|
313
|
+ return list;
|
|
314
|
+ }
|
|
315
|
+
|
|
316
|
+ private List<WeekDto> GetRegion(List<WeekDto> list)
|
|
317
|
+ {
|
|
318
|
+ ProvinceRepository province = new ProvinceRepository(_dbContext);
|
|
319
|
+ Province prov = null;
|
|
320
|
+ foreach(var item in list)
|
|
321
|
+ {
|
|
322
|
+ prov = province.GetDetailed(x => x.Code == item.Region.RegionCode);
|
|
323
|
+ item.Region = new RegionDto(prov.Id, prov.Code, prov.Description);
|
|
324
|
+ }
|
|
325
|
+ return list;
|
|
326
|
+ }
|
|
327
|
+
|
|
328
|
+ private string ChangeRegion(string value)
|
|
329
|
+ {
|
|
330
|
+ switch(value)
|
|
331
|
+ {
|
|
332
|
+ case "FN":
|
|
333
|
+ return "KZN";
|
|
334
|
+ default:
|
|
335
|
+ return value;
|
|
336
|
+ }
|
|
337
|
+ }
|
274
|
338
|
}
|
275
|
339
|
}
|