浏览代码

Propery Search & Carousel changes.

master
George Williams 5 年前
父节点
当前提交
2a3bb44082

+ 17
- 12
UnivateProperties_API/Containers/Property/ImageFormatter.cs 查看文件

@@ -35,25 +35,30 @@ namespace UnivateProperties_API.Containers.Property
35 35
 
36 36
         public static string ImageToBase64(string Path)
37 37
         {
38
-            using (Image image = Image.FromFile(Path))
38
+            if (File.Exists(Path))
39 39
             {
40
-                using (MemoryStream m = new MemoryStream())
40
+                using (Image image = Image.FromFile(Path))
41 41
                 {
42
-                    image.Save(m, image.RawFormat);
43
-                    byte[] imageBytes = m.ToArray();
42
+                    using (MemoryStream m = new MemoryStream())
43
+                    {
44
+                        image.Save(m, image.RawFormat);
45
+                        byte[] imageBytes = m.ToArray();
44 46
 
45
-                    string base64String = Convert.ToBase64String(imageBytes);
47
+                        string base64String = Convert.ToBase64String(imageBytes);
46 48
 
47
-                    if (Path.EndsWith(".jpg") || Path.EndsWith(".jpeg"))
48
-                        base64String = "data:image/jpeg;base64," + base64String;
49
-                    if (Path.EndsWith(".gif"))
50
-                        base64String = "data:image/gif;base64," + base64String;
51
-                    if (base64String.EndsWith(".png"))
52
-                        base64String = "data:image/png;base64," + base64String;
49
+                        if (Path.EndsWith(".jpg") || Path.EndsWith(".jpeg"))
50
+                            base64String = "data:image/jpeg;base64," + base64String;
51
+                        if (Path.EndsWith(".gif"))
52
+                            base64String = "data:image/gif;base64," + base64String;
53
+                        if (base64String.EndsWith(".png"))
54
+                            base64String = "data:image/png;base64," + base64String;
53 55
 
54
-                    return base64String;
56
+                        return base64String;
57
+                    }
55 58
                 }
56 59
             }
60
+            else
61
+                return "";
57 62
         }
58 63
     }
59 64
 }

+ 1
- 1
UnivateProperties_API/Controllers/Misc/CarouselController.cs 查看文件

@@ -25,7 +25,7 @@ namespace UnivateProperties_API.Controllers.Misc
25 25
         [HttpGet("{id}")]
26 26
         public IActionResult Get(int id)
27 27
         {
28
-            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
28
+            return new OkObjectResult(_Repo.GetCarousel(id));
29 29
         }        
30 30
 
31 31
         [HttpPost]

+ 36
- 2
UnivateProperties_API/Repository/Misc/CarouselRepository.cs 查看文件

@@ -77,7 +77,7 @@ namespace UnivateProperties_API.Repository.Misc
77 77
             }
78 78
             if (saveFiles)
79 79
             {
80
-                string path = ImageFormatter.Base64ToImage(item.Image, loc, lastID.ToString());
80
+                string path = ImageFormatter.Base64ToImage(image, loc, lastID.ToString());
81 81
                 item.Image = path;
82 82
             }
83 83
 
@@ -142,12 +142,13 @@ namespace UnivateProperties_API.Repository.Misc
142 142
             var CarouselList = dBContext.Carousel.ToList();
143 143
 
144 144
             foreach (var item in CarouselList)
145
-            {
145
+            {                
146 146
                 if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
147 147
                     item.Image = ImageFormatter.ImageToBase64(item.Image);
148 148
 
149 149
                 var carItem = new CarouselList()
150 150
                 {
151
+                    Id = item.Id,
151 152
                     Image = item.Image,
152 153
                     Header = item.Header
153 154
                 };
@@ -172,5 +173,38 @@ namespace UnivateProperties_API.Repository.Misc
172 173
 
173 174
             return list;
174 175
         }
176
+
177
+        public CarouselList GetCarousel(int id)
178
+        {
179
+            var carousel = dBContext.Carousel.Where(c => c.Id == id).FirstOrDefault();
180
+
181
+            CarouselList item = new CarouselList();
182
+            if (carousel != null)
183
+            {
184
+                foreach (string prop in carousel.GetAllProperties())
185
+                {
186
+                    if (prop != "Item" && prop != "Display")
187
+                        item[prop] = carousel[prop];
188
+                }
189
+
190
+                if (item.PropertyId > 0)
191
+                {
192
+                    var property = dBContext.Properties.Include("Province").Include("City").Include("Suburb").Where(p => p.Id == item.PropertyId).FirstOrDefault();
193
+                    item.Address = string.Format("{0}, {1} <br/>{2}", property.Suburb.Description, property.City.Description, property.AddressLine3);
194
+                    item.IsProperty = true;
195
+                }
196
+                if (item.TimeshareId > 0)
197
+                {
198
+                    var timeshare = dBContext.Weeks.Where(t => t.Id == item.TimeshareId).FirstOrDefault();
199
+                    item.Bedrooms = timeshare.Bedrooms;
200
+                    item.Sleeps = timeshare.MaxSleep;
201
+                    item.Arrival = timeshare.ArrivalDate;
202
+                    item.Departure = timeshare.DepartureDate;
203
+                    item.IsProperty = false;
204
+                }
205
+            }
206
+
207
+            return item;
208
+        }
175 209
     }
176 210
 }

+ 1
- 0
UnivateProperties_API/Repository/Misc/ICarouselRepository.cs 查看文件

@@ -7,5 +7,6 @@ namespace UnivateProperties_API.Repository.Misc
7 7
     public interface ICarouselRepository : IRepository<Carousel>
8 8
     {
9 9
         List<CarouselList> GetCarouselItems();
10
+        CarouselList GetCarousel(int id);
10 11
     }
11 12
 }

正在加载...
取消
保存