|
@@ -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
|
|
@@ -155,8 +157,14 @@ namespace UnivateProperties_API.Repository.Properties
|
155
|
157
|
|
156
|
158
|
if (images != null)
|
157
|
159
|
{
|
|
160
|
+ var lastID = (from p in dBContext.PropertyImages
|
|
161
|
+ orderby p.Id descending
|
|
162
|
+ select p.Id).FirstOrDefault();
|
|
163
|
+
|
158
|
164
|
foreach (PropertyImage image in images)
|
159
|
165
|
{
|
|
166
|
+ lastID++;
|
|
167
|
+ image.Id = lastID;
|
160
|
168
|
image.PropertyId = item.Id;
|
161
|
169
|
dBContext.PropertyImages.Add(image);
|
162
|
170
|
Save();
|
|
@@ -241,16 +249,14 @@ namespace UnivateProperties_API.Repository.Properties
|
241
|
249
|
|
242
|
250
|
return GetDisplayDetails(props);
|
243
|
251
|
}
|
244
|
|
-
|
|
252
|
+
|
245
|
253
|
public List<PropertyDisplay> GetDisplay(PropertySearch search)
|
246
|
254
|
{
|
247
|
|
- //Save to Log
|
248
|
|
- dBContext.SearchLogs.Add(new Model.Logging.SearchLog()
|
|
255
|
+ SearchObject obj = new SearchObject()
|
249
|
256
|
{
|
250
|
|
- Type = "Property",
|
251
|
|
- Search = JsonConvert.SerializeObject(search)
|
252
|
|
- });
|
253
|
|
- Save();
|
|
257
|
+ UserName = search.UserName,
|
|
258
|
+ Type = "Property"
|
|
259
|
+ };
|
254
|
260
|
|
255
|
261
|
if (!string.IsNullOrEmpty(search.Keyword) && search.Keyword.ToUpper() != "ALL")
|
256
|
262
|
{
|
|
@@ -267,6 +273,9 @@ namespace UnivateProperties_API.Repository.Properties
|
267
|
273
|
|| EF.Functions.Like(s.Description.ToLower(), $"%{keyword}%")
|
268
|
274
|
|| EF.Functions.Like(pt.Description.ToLower(), $"%{keyword}%")
|
269
|
275
|
select p).ToList();
|
|
276
|
+ obj.Property = "Keyword";
|
|
277
|
+ obj.Value = search.Keyword;
|
|
278
|
+ SaveLog(obj);
|
270
|
279
|
|
271
|
280
|
return GetDisplayDetails(props);
|
272
|
281
|
}
|
|
@@ -275,7 +284,7 @@ namespace UnivateProperties_API.Repository.Properties
|
275
|
284
|
List<Property> props;
|
276
|
285
|
PropertyUsageType uType = PropertyUsageType.Both;
|
277
|
286
|
|
278
|
|
- if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined")
|
|
287
|
+ if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
|
279
|
288
|
{
|
280
|
289
|
if (search.PropertyUsageType.ToUpper() == "COMMERCIAL")
|
281
|
290
|
uType = PropertyUsageType.Commercial;
|
|
@@ -287,12 +296,20 @@ namespace UnivateProperties_API.Repository.Properties
|
287
|
296
|
where pt.UsageType == uType
|
288
|
297
|
select p).ToList();
|
289
|
298
|
|
|
299
|
+ obj.Property = "PropertyUsageType";
|
|
300
|
+ obj.Value = search.PropertyUsageType;
|
|
301
|
+ SaveLog(obj);
|
|
302
|
+
|
290
|
303
|
if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
|
291
|
304
|
{
|
292
|
305
|
if (search.SalesType.ToUpper() == "SALE")
|
293
|
306
|
props = props.Where(p => p.IsSale).ToList();
|
294
|
307
|
else
|
295
|
308
|
props = props.Where(p => !p.IsSale).ToList();
|
|
309
|
+
|
|
310
|
+ obj.Property = "SalesType";
|
|
311
|
+ obj.Value = search.SalesType;
|
|
312
|
+ SaveLog(obj);
|
296
|
313
|
}
|
297
|
314
|
|
298
|
315
|
if (!string.IsNullOrEmpty(search.Province) && search.Province != "undefined" && search.Province.ToUpper() != "ALL")
|
|
@@ -301,6 +318,10 @@ namespace UnivateProperties_API.Repository.Properties
|
301
|
318
|
join pp in dBContext.Provinces on p.ProvinceId equals pp.Id
|
302
|
319
|
where pp.Description.ToUpper() == search.Province.ToUpper()
|
303
|
320
|
select p).ToList();
|
|
321
|
+
|
|
322
|
+ obj.Property = "Province";
|
|
323
|
+ obj.Value = search.Province;
|
|
324
|
+ SaveLog(obj);
|
304
|
325
|
}
|
305
|
326
|
|
306
|
327
|
if (!string.IsNullOrEmpty(search.City) && search.City != "undefined" && search.City.ToUpper() != "ALL")
|
|
@@ -309,6 +330,10 @@ namespace UnivateProperties_API.Repository.Properties
|
309
|
330
|
join c in dBContext.Cities on p.CityId equals c.Id
|
310
|
331
|
where c.Description.ToUpper() == search.City.ToUpper()
|
311
|
332
|
select p).ToList();
|
|
333
|
+
|
|
334
|
+ obj.Property = "City";
|
|
335
|
+ obj.Value = search.City;
|
|
336
|
+ SaveLog(obj);
|
312
|
337
|
}
|
313
|
338
|
|
314
|
339
|
if (!string.IsNullOrEmpty(search.Suburb) && search.Suburb != "undefined" && search.Suburb.ToUpper() != "ALL")
|
|
@@ -317,6 +342,10 @@ namespace UnivateProperties_API.Repository.Properties
|
317
|
342
|
join s in dBContext.Suburbs on p.SuburbId equals s.Id
|
318
|
343
|
where s.Description.ToUpper() == search.Suburb.ToUpper()
|
319
|
344
|
select p).ToList();
|
|
345
|
+
|
|
346
|
+ obj.Property = "Suburb";
|
|
347
|
+ obj.Value = search.Suburb;
|
|
348
|
+ SaveLog(obj);
|
320
|
349
|
}
|
321
|
350
|
if (!string.IsNullOrEmpty(search.PropertyType) && search.PropertyType != "Undefined" && search.PropertyType.ToUpper() != "ALL")
|
322
|
351
|
{
|
|
@@ -325,12 +354,43 @@ namespace UnivateProperties_API.Repository.Properties
|
325
|
354
|
{
|
326
|
355
|
props = props.Where(p => p.PropertyTypeId == pType.Id).ToList();
|
327
|
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);
|
328
|
377
|
}
|
329
|
378
|
|
330
|
379
|
return GetDisplayDetails(props);
|
331
|
380
|
}
|
332
|
381
|
}
|
333
|
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
|
+
|
334
|
394
|
private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
|
335
|
395
|
{
|
336
|
396
|
var properties = new List<PropertyDisplay>();
|
|
@@ -376,7 +436,10 @@ namespace UnivateProperties_API.Repository.Properties
|
376
|
436
|
where s.Id == item.SuburbId
|
377
|
437
|
select s.Description).FirstOrDefault(),
|
378
|
438
|
Price = item.Price,
|
379
|
|
- 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()
|
380
|
443
|
};
|
381
|
444
|
|
382
|
445
|
if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))
|