|
@@ -0,0 +1,72 @@
|
|
1
|
+using Newtonsoft.Json;
|
|
2
|
+using RestSharp;
|
|
3
|
+using System;
|
|
4
|
+using System.Collections.Generic;
|
|
5
|
+using System.Linq;
|
|
6
|
+using System.Security.Cryptography;
|
|
7
|
+using System.Threading.Tasks;
|
|
8
|
+using UnivateProperties_API.Containers.Timeshare;
|
|
9
|
+using UnivateProperties_API.Context;
|
|
10
|
+using UnivateProperties_API.Helpers;
|
|
11
|
+
|
|
12
|
+namespace UnivateProperties_API.Repository.Timeshare
|
|
13
|
+{
|
|
14
|
+ public interface IResortRepository
|
|
15
|
+ {
|
|
16
|
+ List<ResortDisplay> GetResortsByRegion(string regionCode);
|
|
17
|
+ }
|
|
18
|
+
|
|
19
|
+ public class ResortRepository : IResortRepository
|
|
20
|
+ {
|
|
21
|
+ private readonly DataContext _dbContext;
|
|
22
|
+
|
|
23
|
+ public ResortRepository(DataContext dbContext)
|
|
24
|
+ {
|
|
25
|
+ _dbContext = dbContext;
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ public List<ResortDisplay> GetResortsByRegion(string regionCode)
|
|
29
|
+ {
|
|
30
|
+ var resorts = new List<ResortDisplay>();
|
|
31
|
+ List<UniPointResorts> UniResorts = new List<UniPointResorts>();
|
|
32
|
+ WeekRepository weekRepo = new WeekRepository(_dbContext);
|
|
33
|
+ var weeks = weekRepo.GetDtoListAll();
|
|
34
|
+
|
|
35
|
+ var client = new RestClient(string.Format("https://www.tradeunipoint.com/unibackend/seam/resource/rest/products/resorts/{0}", regionCode))
|
|
36
|
+ {
|
|
37
|
+ Timeout = -1
|
|
38
|
+ };
|
|
39
|
+ var request = new RestRequest(Method.GET);
|
|
40
|
+ IRestResponse response = client.Execute(request);
|
|
41
|
+ UniResorts = JsonConvert.DeserializeObject<List<UniPointResorts>>(response.Content);
|
|
42
|
+
|
|
43
|
+ foreach(var resort in UniResorts)
|
|
44
|
+ {
|
|
45
|
+ if (!string.IsNullOrEmpty(resort.ResortCode))
|
|
46
|
+ {
|
|
47
|
+ ResortDisplay desp = new ResortDisplay()
|
|
48
|
+ {
|
|
49
|
+ ResortCode = resort.ResortCode,
|
|
50
|
+ ResortName = resort.ResortName
|
|
51
|
+ };
|
|
52
|
+ var imgClient = new RestClient(string.Format("https://www.tradeunipoint.com/unibackend/seam/resource/rest/products/{0}/image/1", resort.ResortCode))
|
|
53
|
+ {
|
|
54
|
+ Timeout = -1
|
|
55
|
+ };
|
|
56
|
+ var imgRequest = new RestRequest(Method.GET);
|
|
57
|
+ IRestResponse resp = imgClient.Execute(imgRequest);
|
|
58
|
+ desp.ResortImage = resp.Content;
|
|
59
|
+
|
|
60
|
+ if (desp.ResortImage != "")
|
|
61
|
+ desp.ResortImage = string.Format("data:image/jpeg;base64,{0}", desp.ResortImage);
|
|
62
|
+
|
|
63
|
+ desp.WeeksAvailable = weeks.Where(w => w.Resort.ResortCode == resort.ResortCode).Count();
|
|
64
|
+
|
|
65
|
+ resorts.Add(desp);
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ return resorts.OrderBy(r => r.ResortCode).ToList();
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+}
|