Kaynağa Gözat

To Buy Resorts screen

master
George Williams 4 yıl önce
ebeveyn
işleme
5ae98afad3

+ 10
- 0
UnivateProperties_API/Containers/Timeshare/ResortDisplay.cs Dosyayı Görüntüle

@@ -0,0 +1,10 @@
1
+namespace UnivateProperties_API.Containers.Timeshare
2
+{
3
+    public class ResortDisplay
4
+    {
5
+        public string ResortCode { get; set; }
6
+        public string ResortName { get; set; }
7
+        public string ResortImage { get; set; }
8
+        public int WeeksAvailable { get; set; }
9
+    }
10
+}

+ 29
- 0
UnivateProperties_API/Controllers/Timeshare/ResortController.cs Dosyayı Görüntüle

@@ -0,0 +1,29 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using Microsoft.AspNetCore.Mvc;
6
+using UnivateProperties_API.Repository.Timeshare;
7
+
8
+// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
9
+
10
+namespace UnivateProperties_API.Controllers.Timeshare
11
+{
12
+    [Route("api/[controller]")]
13
+    [ApiController]
14
+    public class ResortController : ControllerBase
15
+    {
16
+        private readonly IResortRepository _Repo;
17
+
18
+        public ResortController(IResortRepository repo)
19
+        {
20
+            _Repo = repo;
21
+        }
22
+
23
+        [HttpGet("{regionCode}")]
24
+        public IActionResult Get(string regionCode)
25
+        {
26
+            return new OkObjectResult(_Repo.GetResortsByRegion(regionCode));
27
+        }
28
+    }
29
+}

+ 72
- 0
UnivateProperties_API/Repository/Timeshare/IResortRepository.cs Dosyayı Görüntüle

@@ -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
+}

+ 1
- 0
UnivateProperties_API/Startup.cs Dosyayı Görüntüle

@@ -138,6 +138,7 @@ namespace UnivateProperties_API
138 138
             services.AddTransient<IWeekRepository, WeekRepository>();
139 139
             services.AddTransient<IRepository<Bank>, BankAccountRepository>();
140 140
             services.AddTransient<IRepository<BankAccount>, BankAccountRepository>();
141
+            services.AddTransient<IResortRepository, ResortRepository>();
141 142
             #endregion Timeshare
142 143
             #region User
143 144
             services.AddScoped<IRegisterRepository, RegisterRepository>();

Loading…
İptal
Kaydet