|
@@ -1,4 +1,5 @@
|
1
|
1
|
using Microsoft.EntityFrameworkCore;
|
|
2
|
+using Newtonsoft.Json;
|
2
|
3
|
using System;
|
3
|
4
|
using System.Collections.Generic;
|
4
|
5
|
using System.Linq;
|
|
@@ -241,84 +242,94 @@ namespace UnivateProperties_API.Repository.Properties
|
241
|
242
|
return GetDisplayDetails(props);
|
242
|
243
|
}
|
243
|
244
|
|
244
|
|
- public List<PropertyDisplay> GetDisplay(string Keyword)
|
|
245
|
+ public List<PropertyDisplay> GetDisplay(PropertySearch search)
|
245
|
246
|
{
|
246
|
|
- Keyword = Keyword.ToLower();
|
247
|
|
-
|
248
|
|
- List<Property> props = (from p in dBContext.Properties
|
249
|
|
- join pr in dBContext.Provinces on p.ProvinceId equals pr.Id
|
250
|
|
- join c in dBContext.Cities on p.CityId equals c.Id
|
251
|
|
- join s in dBContext.Suburbs on p.SuburbId equals s.Id
|
252
|
|
- join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
|
253
|
|
- where EF.Functions.Like(p.PropertyName.ToLower(), $"%{Keyword}%")
|
254
|
|
- || EF.Functions.Like(pr.Description.ToLower(), $"%{Keyword}%")
|
255
|
|
- || EF.Functions.Like(c.Description.ToLower(), $"%{Keyword}%")
|
256
|
|
- || EF.Functions.Like(s.Description.ToLower(), $"%{Keyword}%")
|
257
|
|
- || EF.Functions.Like(pt.Description.ToLower(), $"%{Keyword}%")
|
258
|
|
- select p).ToList();
|
259
|
|
-
|
260
|
|
- return GetDisplayDetails(props);
|
261
|
|
- }
|
262
|
|
-
|
263
|
|
- public List<PropertyDisplay> GetDisplay(string type, string propertyType, string province, string city, string suburb, string propType)
|
264
|
|
- {
|
265
|
|
- List<Property> props;
|
266
|
|
- PropertyUsageType uType = PropertyUsageType.Both;
|
267
|
|
-
|
268
|
|
- if (propertyType != "" && propertyType != "undefined")
|
|
247
|
+ //Save to Log
|
|
248
|
+ dBContext.SearchLogs.Add(new Model.Logging.SearchLog()
|
269
|
249
|
{
|
270
|
|
- if (propertyType.ToUpper() == "COMMERCIAL")
|
271
|
|
- uType = PropertyUsageType.Commercial;
|
272
|
|
- else
|
273
|
|
- uType = PropertyUsageType.Residential;
|
274
|
|
- }
|
275
|
|
- props = (from p in dBContext.Properties
|
276
|
|
- join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
|
277
|
|
- where pt.UsageType == uType
|
278
|
|
- select p).ToList();
|
|
250
|
+ UserID = search.UserID,
|
|
251
|
+ Search = JsonConvert.SerializeObject(search)
|
|
252
|
+ });
|
|
253
|
+ Save();
|
279
|
254
|
|
280
|
|
- if (type != "" && type != "undefined")
|
|
255
|
+ if (!string.IsNullOrEmpty(search.Keyword))
|
281
|
256
|
{
|
282
|
|
- if (type.ToUpper() == "SALE")
|
283
|
|
- props = props.Where(p => p.IsSale).ToList();
|
284
|
|
- else
|
285
|
|
- props = props.Where(p => !p.IsSale).ToList();
|
|
257
|
+ string keyword = search.Keyword.ToLower();
|
|
258
|
+
|
|
259
|
+ List<Property> props = (from p in dBContext.Properties
|
|
260
|
+ join pr in dBContext.Provinces on p.ProvinceId equals pr.Id
|
|
261
|
+ join c in dBContext.Cities on p.CityId equals c.Id
|
|
262
|
+ join s in dBContext.Suburbs on p.SuburbId equals s.Id
|
|
263
|
+ join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
|
|
264
|
+ where EF.Functions.Like(p.PropertyName.ToLower(), $"%{keyword}%")
|
|
265
|
+ || EF.Functions.Like(pr.Description.ToLower(), $"%{keyword}%")
|
|
266
|
+ || EF.Functions.Like(c.Description.ToLower(), $"%{keyword}%")
|
|
267
|
+ || EF.Functions.Like(s.Description.ToLower(), $"%{keyword}%")
|
|
268
|
+ || EF.Functions.Like(pt.Description.ToLower(), $"%{keyword}%")
|
|
269
|
+ select p).ToList();
|
|
270
|
+
|
|
271
|
+ return GetDisplayDetails(props);
|
286
|
272
|
}
|
287
|
|
-
|
288
|
|
- if (province != "" && province != "undefined" && province.ToUpper() != "ALL")
|
|
273
|
+ else
|
289
|
274
|
{
|
290
|
|
- props = (from p in props
|
291
|
|
- join pp in dBContext.Provinces on p.ProvinceId equals pp.Id
|
292
|
|
- where pp.Description.ToUpper() == province.ToUpper()
|
293
|
|
- select p).ToList();
|
294
|
|
- }
|
|
275
|
+ List<Property> props;
|
|
276
|
+ PropertyUsageType uType = PropertyUsageType.Both;
|
295
|
277
|
|
296
|
|
- if (city != "" && city != "undefined" && city.ToUpper() != "ALL")
|
297
|
|
- {
|
298
|
|
- props = (from p in props
|
299
|
|
- join c in dBContext.Cities on p.CityId equals c.Id
|
300
|
|
- where c.Description.ToUpper() == city.ToUpper()
|
|
278
|
+ if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined")
|
|
279
|
+ {
|
|
280
|
+ if (search.PropertyUsageType.ToUpper() == "COMMERCIAL")
|
|
281
|
+ uType = PropertyUsageType.Commercial;
|
|
282
|
+ else
|
|
283
|
+ uType = PropertyUsageType.Residential;
|
|
284
|
+ }
|
|
285
|
+ props = (from p in dBContext.Properties
|
|
286
|
+ join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
|
|
287
|
+ where pt.UsageType == uType
|
301
|
288
|
select p).ToList();
|
302
|
|
- }
|
303
|
289
|
|
304
|
|
- if (suburb != "" && suburb != "undefined" && suburb.ToUpper() != "ALL")
|
305
|
|
- {
|
306
|
|
- props = (from p in props
|
307
|
|
- join s in dBContext.Suburbs on p.SuburbId equals s.Id
|
308
|
|
- where s.Description.ToUpper() == suburb.ToUpper()
|
309
|
|
- select p).ToList();
|
310
|
|
- }
|
311
|
|
- if (propType != "" && propType != "Undefined" && propType.ToUpper() != "ALL")
|
312
|
|
- {
|
313
|
|
- var pType = dBContext.PropertyTypes.Where(t => t.Description == propType).FirstOrDefault();
|
314
|
|
- if (pType != null)
|
|
290
|
+ if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
|
315
|
291
|
{
|
316
|
|
- props = props.Where(p => p.PropertyTypeId == pType.Id).ToList();
|
|
292
|
+ if (search.SalesType.ToUpper() == "SALE")
|
|
293
|
+ props = props.Where(p => p.IsSale).ToList();
|
|
294
|
+ else
|
|
295
|
+ props = props.Where(p => !p.IsSale).ToList();
|
317
|
296
|
}
|
318
|
|
- }
|
319
|
297
|
|
320
|
|
- return GetDisplayDetails(props);
|
321
|
|
- }
|
|
298
|
+ if (!string.IsNullOrEmpty(search.Province) && search.Province != "undefined" && search.Province.ToUpper() != "ALL")
|
|
299
|
+ {
|
|
300
|
+ props = (from p in props
|
|
301
|
+ join pp in dBContext.Provinces on p.ProvinceId equals pp.Id
|
|
302
|
+ where pp.Description.ToUpper() == search.Province.ToUpper()
|
|
303
|
+ select p).ToList();
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+ if (!string.IsNullOrEmpty(search.City) && search.City != "undefined" && search.City.ToUpper() != "ALL")
|
|
307
|
+ {
|
|
308
|
+ props = (from p in props
|
|
309
|
+ join c in dBContext.Cities on p.CityId equals c.Id
|
|
310
|
+ where c.Description.ToUpper() == search.City.ToUpper()
|
|
311
|
+ select p).ToList();
|
|
312
|
+ }
|
|
313
|
+
|
|
314
|
+ if (!string.IsNullOrEmpty(search.Suburb) && search.Suburb != "undefined" && search.Suburb.ToUpper() != "ALL")
|
|
315
|
+ {
|
|
316
|
+ props = (from p in props
|
|
317
|
+ join s in dBContext.Suburbs on p.SuburbId equals s.Id
|
|
318
|
+ where s.Description.ToUpper() == search.Suburb.ToUpper()
|
|
319
|
+ select p).ToList();
|
|
320
|
+ }
|
|
321
|
+ if (!string.IsNullOrEmpty(search.PropertyType) && search.PropertyType != "Undefined" && search.PropertyType.ToUpper() != "ALL")
|
|
322
|
+ {
|
|
323
|
+ var pType = dBContext.PropertyTypes.Where(t => t.Description == search.PropertyType).FirstOrDefault();
|
|
324
|
+ if (pType != null)
|
|
325
|
+ {
|
|
326
|
+ props = props.Where(p => p.PropertyTypeId == pType.Id).ToList();
|
|
327
|
+ }
|
|
328
|
+ }
|
|
329
|
+
|
|
330
|
+ return GetDisplayDetails(props);
|
|
331
|
+ }
|
|
332
|
+ }
|
322
|
333
|
|
323
|
334
|
private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
|
324
|
335
|
{
|
|
@@ -428,6 +439,6 @@ namespace UnivateProperties_API.Repository.Properties
|
428
|
439
|
}
|
429
|
440
|
|
430
|
441
|
return list;
|
431
|
|
- }
|
|
442
|
+ }
|
432
|
443
|
}
|
433
|
444
|
}
|