Просмотр исходного кода

Property Search + Search logs

master
George Williams 5 лет назад
Родитель
Сommit
12497e9949

+ 2
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Просмотреть файл

@@ -6,6 +6,7 @@ namespace UnivateProperties_API.Containers.Property
6 6
     {
7 7
         #region Properties
8 8
         public int Id { get; set; }
9
+        public string PropertyUsageType { get; set; }
9 10
         public string ShortDescription { get; set; }
10 11
         public bool IsSale { get; set; }
11 12
         public string DisplayPrice { get; set; }
@@ -29,7 +30,7 @@ namespace UnivateProperties_API.Containers.Property
29 30
         public string City { get; set; }
30 31
         public string Suburb { get; set; }
31 32
         public string DisplayImage { get; set; }
32
-        public decimal Price { get; set; }
33
+        public decimal Price { get; set; }        
33 34
         public DateTime DateCreated { get; set; }
34 35
         #endregion 
35 36
     }

+ 2
- 0
UnivateProperties_API/Containers/Property/PropertySearch.cs Просмотреть файл

@@ -11,6 +11,8 @@
11 11
         public string Province { get; set; }
12 12
         public string City { get; set; }
13 13
         public string Suburb { get; set; }
14
+        public decimal MinPrice { get; set; }
15
+        public decimal MaxPrice { get; set; }
14 16
         #endregion 
15 17
     }
16 18
 }

+ 2
- 1
UnivateProperties_API/Containers/Timeshare/TimeshareSearch.cs Просмотреть файл

@@ -1,8 +1,9 @@
1 1
 namespace UnivateProperties_API.Containers.Timeshare
2 2
 {
3
-    public class TimeshareSearch
3
+    public class SearchObject
4 4
     {
5 5
         public string UserName { get; set; }
6
+        public string Type { get; set; }
6 7
         public string Property { get; set; }
7 8
         public string Value { get; set; }
8 9
     }

+ 2
- 1
UnivateProperties_API/Containers/Timeshare/TimeshareSearchDisplay.cs Просмотреть файл

@@ -2,9 +2,10 @@
2 2
 
3 3
 namespace UnivateProperties_API.Containers.Timeshare
4 4
 {
5
-    public class TimeshareSearchDisplay
5
+    public class SearchDisplay
6 6
     {
7 7
         public string UserName { get; set; }
8
+        public string Type { get; set; }
8 9
         public DateTime Date { get; set; }
9 10
         public string Property { get; set; }
10 11
         public string Value { get; set; }

+ 6
- 10
UnivateProperties_API/Controllers/Logging/SearchLogController.cs Просмотреть файл

@@ -17,23 +17,19 @@ namespace UnivateProperties_API.Controllers.Logging
17 17
         }
18 18
       
19 19
 
20
-        [HttpGet("{type}")]
21
-        public IActionResult Get(string type)
22
-        {
23
-            if (type.ToUpper() == "PROPERTY")
24
-                return new OkObjectResult(_Repo.GetPropertySearches());
25
-            else if (type.ToUpper() == "TIMESHARE")
26
-                return new OkObjectResult(_Repo.GetTimeshareSearches());
27
-            else return NoContent();
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {      
23
+            return new OkObjectResult(_Repo.GetSearches());
28 24
         }
29 25
         
30 26
 
31 27
         [HttpPost]
32
-        public IActionResult Post([FromBody] TimeshareSearch item)
28
+        public IActionResult Post([FromBody] SearchObject item)
33 29
         {
34 30
             using (var scope = new TransactionScope())
35 31
             {
36
-                _Repo.SaveTimeshareSearch(item);
32
+                _Repo.SaveSearch(item);
37 33
                 scope.Complete();
38 34
                 return new OkObjectResult(item);
39 35
             }

+ 6
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs Просмотреть файл

@@ -78,15 +78,15 @@ namespace UnivateProperties_API.Controllers.Properties
78 78
         }
79 79
         #endregion
80 80
 
81
-        [HttpPost("search")]
81
+        [HttpGet("search")]
82 82
         public IActionResult Search([FromBody] PropertySearch search)
83 83
         {
84 84
             return new OkObjectResult(_Repo.GetDisplay(search));
85 85
         }
86 86
 
87 87
         //Will need to come out. Post search not working......:(
88
-        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}")]
89
-        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb)
88
+        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
89
+        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
90 90
         {
91 91
             var search = new PropertySearch()
92 92
             {
@@ -97,7 +97,9 @@ namespace UnivateProperties_API.Controllers.Properties
97 97
                 PropertyType = propertyType,
98 98
                 Province = province,
99 99
                 City = city,
100
-                Suburb = suburb
100
+                Suburb = suburb,
101
+                MinPrice = minPrice,
102
+                MaxPrice = maxPrice
101 103
             };
102 104
 
103 105
             return new OkObjectResult(_Repo.GetDisplay(search));

+ 2
- 3
UnivateProperties_API/Repository/Logging/ISearchLogRepository.cs Просмотреть файл

@@ -7,8 +7,7 @@ namespace UnivateProperties_API.Repository.Logging
7 7
 {
8 8
     public interface ISearchLogRepository: IRepository<SearchLog>
9 9
     {
10
-        List<TimeshareSearchDisplay> GetTimeshareSearches();
11
-        List<PropertySearchDispaly> GetPropertySearches();
12
-        void SaveTimeshareSearch(TimeshareSearch item);
10
+        List<SearchDisplay> GetSearches();        
11
+        void SaveSearch(SearchObject item);
13 12
     }
14 13
 }

+ 15
- 38
UnivateProperties_API/Repository/Logging/SearchLogRepository.cs Просмотреть файл

@@ -39,44 +39,21 @@ namespace UnivateProperties_API.Repository.Logging
39 39
         public List<SearchLog> GetDetailedAll()
40 40
         {
41 41
             return _dbContext.SearchLogs.ToList();
42
-        }
42
+        }        
43 43
 
44
-        public List<PropertySearchDispaly> GetPropertySearches()
44
+        public List<SearchDisplay> GetSearches()
45 45
         {
46
-            var list = new List<PropertySearchDispaly>();
47
-            var logs = Get(x => x.Type == "Property");
46
+            var list = new List<SearchDisplay>();
47
+            var logs = GetAll();
48 48
             foreach (SearchLog log in logs)
49 49
             {
50
-                var propSearch = JsonConvert.DeserializeObject<PropertySearch>(log.Search);
51
-                list.Add(new PropertySearchDispaly()
52
-                {
50
+                var searchObject = JsonConvert.DeserializeObject<SearchObject>(log.Search);
51
+                list.Add(new SearchDisplay() {
53 52
                     Date = log.Created,
54
-                    UserName = propSearch.UserName,
55
-                    Keyword = propSearch.Keyword,
56
-                    SalesType = propSearch.SalesType,
57
-                    PropertyUsageType = propSearch.PropertyUsageType,
58
-                    PropertyType = propSearch.PropertyType,
59
-                    Province = propSearch.Province,
60
-                    City = propSearch.City,
61
-                    Suburb = propSearch.Suburb
62
-                });
63
-                Debug.WriteLine(propSearch);
64
-            }
65
-            return list;            
66
-        }
67
-
68
-        public List<TimeshareSearchDisplay> GetTimeshareSearches()
69
-        {
70
-            var list = new List<TimeshareSearchDisplay>();
71
-            var logs = Get(x => x.Type == "Timeshare");
72
-            foreach (SearchLog log in logs)
73
-            {
74
-                var timeshareSearch = JsonConvert.DeserializeObject<TimeshareSearch>(log.Search);
75
-                list.Add(new TimeshareSearchDisplay() {
76
-                    Date = log.Created,
77
-                    UserName = timeshareSearch.UserName,
78
-                    Property = timeshareSearch.Property,
79
-                    Value = timeshareSearch.Value
53
+                    Type = log.Type,
54
+                    UserName = searchObject.UserName,
55
+                    Property = searchObject.Property,
56
+                    Value = searchObject.Value
80 57
                 });
81 58
             }
82 59
             return list;
@@ -127,14 +104,14 @@ namespace UnivateProperties_API.Repository.Logging
127 104
             _dbContext.SaveChanges();
128 105
         }
129 106
 
130
-        public void SaveTimeshareSearch(TimeshareSearch item)
131
-        {
107
+        public void SaveSearch(SearchObject item)
108
+        {            
132 109
             var searchLog = new SearchLog
133
-            {
134
-                Type = "Timeshare",
110
+            { 
111
+                Type = item.Type,
135 112
                 Search = JsonConvert.SerializeObject(item)
136 113
             };
137
-            _dbContext.SearchLogs.Remove(searchLog);
114
+            _dbContext.SearchLogs.Add(searchLog);
138 115
             Save();
139 116
         }
140 117
 

+ 66
- 9
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Просмотреть файл

@@ -4,7 +4,9 @@ using System;
4 4
 using System.Collections.Generic;
5 5
 using System.Linq;
6 6
 using UnivateProperties_API.Containers.Property;
7
+using UnivateProperties_API.Containers.Timeshare;
7 8
 using UnivateProperties_API.Context;
9
+using UnivateProperties_API.Model.Logging;
8 10
 using UnivateProperties_API.Model.Properties;
9 11
 
10 12
 namespace UnivateProperties_API.Repository.Properties
@@ -247,16 +249,14 @@ namespace UnivateProperties_API.Repository.Properties
247 249
 
248 250
             return GetDisplayDetails(props);
249 251
         }
250
-
252
+        
251 253
         public List<PropertyDisplay> GetDisplay(PropertySearch search)
252 254
         {
253
-            //Save to Log
254
-            dBContext.SearchLogs.Add(new Model.Logging.SearchLog()
255
+            SearchObject obj = new SearchObject()
255 256
             {
256
-                Type = "Property",
257
-                Search = JsonConvert.SerializeObject(search)
258
-            });
259
-            Save();
257
+                UserName = search.UserName,
258
+                Type = "Property"
259
+            };
260 260
 
261 261
             if (!string.IsNullOrEmpty(search.Keyword) && search.Keyword.ToUpper() != "ALL")
262 262
             {
@@ -273,6 +273,9 @@ namespace UnivateProperties_API.Repository.Properties
273 273
                                         || EF.Functions.Like(s.Description.ToLower(), $"%{keyword}%")
274 274
                                         || EF.Functions.Like(pt.Description.ToLower(), $"%{keyword}%")
275 275
                                         select p).ToList();
276
+                obj.Property = "Keyword";
277
+                obj.Value = search.Keyword;
278
+                SaveLog(obj);
276 279
 
277 280
                 return GetDisplayDetails(props);
278 281
             }
@@ -281,7 +284,7 @@ namespace UnivateProperties_API.Repository.Properties
281 284
                 List<Property> props;
282 285
                 PropertyUsageType uType = PropertyUsageType.Both;
283 286
 
284
-                if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined")
287
+                if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
285 288
                 {
286 289
                     if (search.PropertyUsageType.ToUpper() == "COMMERCIAL")
287 290
                         uType = PropertyUsageType.Commercial;
@@ -293,12 +296,20 @@ namespace UnivateProperties_API.Repository.Properties
293 296
                          where pt.UsageType == uType
294 297
                          select p).ToList();
295 298
 
299
+                obj.Property = "PropertyUsageType";
300
+                obj.Value = search.PropertyUsageType;
301
+                SaveLog(obj);
302
+
296 303
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
297 304
                 {
298 305
                     if (search.SalesType.ToUpper() == "SALE")
299 306
                         props = props.Where(p => p.IsSale).ToList();
300 307
                     else
301 308
                         props = props.Where(p => !p.IsSale).ToList();
309
+
310
+                    obj.Property = "SalesType";
311
+                    obj.Value = search.SalesType;
312
+                    SaveLog(obj);
302 313
                 }
303 314
 
304 315
                 if (!string.IsNullOrEmpty(search.Province) && search.Province != "undefined" && search.Province.ToUpper() != "ALL")
@@ -307,6 +318,10 @@ namespace UnivateProperties_API.Repository.Properties
307 318
                              join pp in dBContext.Provinces on p.ProvinceId equals pp.Id
308 319
                              where pp.Description.ToUpper() == search.Province.ToUpper()
309 320
                              select p).ToList();
321
+
322
+                    obj.Property = "Province";
323
+                    obj.Value = search.Province;
324
+                    SaveLog(obj);
310 325
                 }
311 326
 
312 327
                 if (!string.IsNullOrEmpty(search.City) && search.City != "undefined" && search.City.ToUpper() != "ALL")
@@ -315,6 +330,10 @@ namespace UnivateProperties_API.Repository.Properties
315 330
                              join c in dBContext.Cities on p.CityId equals c.Id
316 331
                              where c.Description.ToUpper() == search.City.ToUpper()
317 332
                              select p).ToList();
333
+
334
+                    obj.Property = "City";
335
+                    obj.Value = search.City;
336
+                    SaveLog(obj);
318 337
                 }
319 338
 
320 339
                 if (!string.IsNullOrEmpty(search.Suburb) && search.Suburb != "undefined" && search.Suburb.ToUpper() != "ALL")
@@ -323,6 +342,10 @@ namespace UnivateProperties_API.Repository.Properties
323 342
                              join s in dBContext.Suburbs on p.SuburbId equals s.Id
324 343
                              where s.Description.ToUpper() == search.Suburb.ToUpper()
325 344
                              select p).ToList();
345
+
346
+                    obj.Property = "Suburb";
347
+                    obj.Value = search.Suburb;
348
+                    SaveLog(obj);
326 349
                 }
327 350
                 if (!string.IsNullOrEmpty(search.PropertyType) && search.PropertyType != "Undefined" && search.PropertyType.ToUpper() != "ALL")
328 351
                 {
@@ -331,12 +354,43 @@ namespace UnivateProperties_API.Repository.Properties
331 354
                     {
332 355
                         props = props.Where(p => p.PropertyTypeId == pType.Id).ToList();
333 356
                     }
357
+
358
+                    obj.Property = "PropertyType";
359
+                    obj.Value = search.PropertyType;
360
+                    SaveLog(obj);
361
+                }
362
+                if (search.MinPrice > 0)
363
+                {
364
+                    props = props.Where(p => p.Price >= search.MinPrice).ToList();
365
+
366
+                    obj.Property = "MinPrice";
367
+                    obj.Value = search.MinPrice.ToString();
368
+                    SaveLog(obj);
369
+                }
370
+                if (search.MaxPrice > 0)
371
+                {
372
+                    props = props.Where(p => p.Price <= search.MaxPrice).ToList();
373
+
374
+                    obj.Property = "MaxPrice";
375
+                    obj.Value = search.MaxPrice.ToString();
376
+                    SaveLog(obj);
334 377
                 }
335 378
 
336 379
                 return GetDisplayDetails(props);
337 380
             }
338 381
         }        
339 382
 
383
+        private void SaveLog(SearchObject item)
384
+        {
385
+            var searchLog = new SearchLog
386
+            {
387
+                Type = item.Type,
388
+                Search = JsonConvert.SerializeObject(item)
389
+            };
390
+            dBContext.SearchLogs.Add(searchLog);
391
+            Save();
392
+        }
393
+
340 394
         private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
341 395
         {
342 396
             var properties = new List<PropertyDisplay>();
@@ -382,7 +436,10 @@ namespace UnivateProperties_API.Repository.Properties
382 436
                               where s.Id == item.SuburbId
383 437
                               select s.Description).FirstOrDefault(),
384 438
                     Price = item.Price,
385
-                    DateCreated = item.Created
439
+                    DateCreated = item.Created,
440
+                    PropertyUsageType = (from p in dBContext.PropertyTypes
441
+                                         where p.Id == item.PropertyTypeId
442
+                                         select p.UsageType.ToString()).FirstOrDefault()
386 443
                 };
387 444
 
388 445
                 if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))

Загрузка…
Отмена
Сохранить