|
@@ -27,7 +27,7 @@ namespace UnivateProperties_API.Repository.Properties
|
27
|
27
|
public List<Property> Get(Func<Property, bool> where)
|
28
|
28
|
{
|
29
|
29
|
return dBContext.Properties
|
30
|
|
- .Include("PropertyType")
|
|
30
|
+ .Include("PropertyType")
|
31
|
31
|
.Where(where).ToList();
|
32
|
32
|
}
|
33
|
33
|
|
|
@@ -39,7 +39,7 @@ namespace UnivateProperties_API.Repository.Properties
|
39
|
39
|
|
40
|
40
|
public Property GetDetailed(Func<Property, bool> first)
|
41
|
41
|
{
|
42
|
|
- throw new NotImplementedException();
|
|
42
|
+ throw new NotImplementedException();
|
43
|
43
|
}
|
44
|
44
|
|
45
|
45
|
public PropertyContainer GetDetailed(int id, bool detailed)
|
|
@@ -72,10 +72,10 @@ namespace UnivateProperties_API.Repository.Properties
|
72
|
72
|
}
|
73
|
73
|
|
74
|
74
|
private PropertyContainer GetDetail(Property property, bool detailed)
|
75
|
|
- {
|
|
75
|
+ {
|
76
|
76
|
int propID = property.Id;
|
77
|
|
- var propertyType = dBContext.PropertyTypes.Find(property.PropertyTypeId);
|
78
|
|
- property.DisplayData = new List<PropertyDetailGroup>();
|
|
77
|
+ var propertyType = dBContext.PropertyTypes.Find(property.PropertyTypeId);
|
|
78
|
+ property.DisplayData = new List<PropertyDetailGroup>();
|
79
|
79
|
|
80
|
80
|
if (detailed)
|
81
|
81
|
{
|
|
@@ -236,7 +236,7 @@ namespace UnivateProperties_API.Repository.Properties
|
236
|
236
|
{
|
237
|
237
|
if (prop != "Item" && prop != "Display")
|
238
|
238
|
property[prop] = item[prop];
|
239
|
|
- }
|
|
239
|
+ }
|
240
|
240
|
|
241
|
241
|
property.PropertyUserFields = null;
|
242
|
242
|
property.PropertyImages = null;
|
|
@@ -244,7 +244,7 @@ namespace UnivateProperties_API.Repository.Properties
|
244
|
244
|
if (item.Price < item.OldPrice)
|
245
|
245
|
{
|
246
|
246
|
property.PriceRedused = true;
|
247
|
|
- }
|
|
247
|
+ }
|
248
|
248
|
|
249
|
249
|
if (!string.IsNullOrEmpty(item.StatusString))
|
250
|
250
|
{
|
|
@@ -252,7 +252,7 @@ namespace UnivateProperties_API.Repository.Properties
|
252
|
252
|
property.StatusDate = DateTime.Now;
|
253
|
253
|
|
254
|
254
|
property.StatusId = dBContext.Status.Where(s => s.Description == item.StatusString && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
255
|
|
- if ((item.StatusString.ToUpper() == "RENTED OUT" || item.StatusString.ToUpper() == "SOLD") && item.StatusString != item.OldStatus)
|
|
255
|
+ if ((item.StatusString.ToUpper() == "RENTED OUT" || item.StatusString.ToUpper() == "SOLD") && item.StatusString != item.OldStatus)
|
256
|
256
|
{
|
257
|
257
|
property.CutOffDisplayDate = DateTime.Now.AddMonths(1);
|
258
|
258
|
}
|
|
@@ -300,7 +300,7 @@ namespace UnivateProperties_API.Repository.Properties
|
300
|
300
|
dBContext.Entry(propField).State = EntityState.Modified;
|
301
|
301
|
Save();
|
302
|
302
|
}
|
303
|
|
- }
|
|
303
|
+ }
|
304
|
304
|
}
|
305
|
305
|
}
|
306
|
306
|
#endregion
|
|
@@ -329,23 +329,30 @@ namespace UnivateProperties_API.Repository.Properties
|
329
|
329
|
}
|
330
|
330
|
|
331
|
331
|
if (item.NewImages != null)
|
332
|
|
- {
|
|
332
|
+ {
|
333
|
333
|
bool saveFiles = false;
|
334
|
334
|
var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
|
335
|
335
|
if (!string.IsNullOrEmpty(loc))
|
336
|
336
|
{
|
337
|
337
|
saveFiles = true;
|
|
338
|
+ if (loc.EndsWith("\\"))
|
|
339
|
+ {
|
|
340
|
+ loc = loc.Substring(0, loc.Length - 1);
|
|
341
|
+ }
|
338
|
342
|
loc += string.Format("\\{0}", property.Id);
|
339
|
|
- if (Directory.Exists(loc))
|
|
343
|
+ if (!Directory.Exists(loc))
|
340
|
344
|
{
|
341
|
345
|
Directory.CreateDirectory(loc);
|
342
|
346
|
}
|
343
|
347
|
}
|
344
|
348
|
|
345
|
|
-
|
|
349
|
+
|
346
|
350
|
var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
|
347
|
351
|
foreach (var image in item.NewImages)
|
348
|
352
|
{
|
|
353
|
+ if (!image.Image.StartsWith("data:image"))
|
|
354
|
+ continue;
|
|
355
|
+
|
349
|
356
|
var propImage = new PropertyImage
|
350
|
357
|
{
|
351
|
358
|
PropertyId = property.Id,
|
|
@@ -366,7 +373,7 @@ namespace UnivateProperties_API.Repository.Properties
|
366
|
373
|
dBContext.PropertyImages.Add(propImage);
|
367
|
374
|
Save();
|
368
|
375
|
lastID++;
|
369
|
|
- }
|
|
376
|
+ }
|
370
|
377
|
}
|
371
|
378
|
}
|
372
|
379
|
|
|
@@ -391,7 +398,7 @@ namespace UnivateProperties_API.Repository.Properties
|
391
|
398
|
|
392
|
399
|
return GetDisplayDetails(props);
|
393
|
400
|
}
|
394
|
|
-
|
|
401
|
+
|
395
|
402
|
public List<PropertyDisplay> GetDisplay(PropertySearch search)
|
396
|
403
|
{
|
397
|
404
|
//return GetDisplayDetails(dBContext.Properties.ToList());
|
|
@@ -410,7 +417,7 @@ namespace UnivateProperties_API.Repository.Properties
|
410
|
417
|
{
|
411
|
418
|
string keyword = search.Keyword.ToLower();
|
412
|
419
|
|
413
|
|
- List<Property> props = (from p in dBContext.Properties
|
|
420
|
+ List<Property> props = (from p in dBContext.Properties
|
414
|
421
|
join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
|
415
|
422
|
where EF.Functions.Like(p.PropertyName.ToLower(), $"%{keyword}%")
|
416
|
423
|
|| EF.Functions.Like(p.Province.ToLower(), $"%{keyword}%")
|
|
@@ -474,7 +481,7 @@ namespace UnivateProperties_API.Repository.Properties
|
474
|
481
|
|
475
|
482
|
if (!string.IsNullOrEmpty(search.Province) && search.Province != "undefined" && search.Province.ToUpper() != "ALL")
|
476
|
483
|
{
|
477
|
|
- props = (from p in props
|
|
484
|
+ props = (from p in props
|
478
|
485
|
where p.Province.ToUpper() == search.Province.ToUpper()
|
479
|
486
|
select p).ToList();
|
480
|
487
|
|
|
@@ -485,7 +492,7 @@ namespace UnivateProperties_API.Repository.Properties
|
485
|
492
|
|
486
|
493
|
if (!string.IsNullOrEmpty(search.City) && search.City != "undefined" && search.City.ToUpper() != "ALL")
|
487
|
494
|
{
|
488
|
|
- props = (from p in props
|
|
495
|
+ props = (from p in props
|
489
|
496
|
where p.City.ToUpper() == search.City.ToUpper()
|
490
|
497
|
select p).ToList();
|
491
|
498
|
|
|
@@ -496,7 +503,7 @@ namespace UnivateProperties_API.Repository.Properties
|
496
|
503
|
|
497
|
504
|
if (!string.IsNullOrEmpty(search.Suburb) && search.Suburb != "undefined" && search.Suburb.ToUpper() != "ALL")
|
498
|
505
|
{
|
499
|
|
- props = (from p in props
|
|
506
|
+ props = (from p in props
|
500
|
507
|
where p.Suburb.ToUpper() == search.Suburb.ToUpper()
|
501
|
508
|
select p).ToList();
|
502
|
509
|
|
|
@@ -544,7 +551,7 @@ namespace UnivateProperties_API.Repository.Properties
|
544
|
551
|
|
545
|
552
|
return GetDisplayDetails(props);
|
546
|
553
|
}
|
547
|
|
- }
|
|
554
|
+ }
|
548
|
555
|
|
549
|
556
|
private void SaveLog(SearchObject item)
|
550
|
557
|
{
|
|
@@ -552,7 +559,7 @@ namespace UnivateProperties_API.Repository.Properties
|
552
|
559
|
{
|
553
|
560
|
Type = item.Type,
|
554
|
561
|
Search = JsonConvert.SerializeObject(item)
|
555
|
|
- };
|
|
562
|
+ };
|
556
|
563
|
dBContext.SearchLogs.Add(searchLog);
|
557
|
564
|
Save();
|
558
|
565
|
}
|
|
@@ -566,7 +573,7 @@ namespace UnivateProperties_API.Repository.Properties
|
566
|
573
|
PropertyDisplay display = new PropertyDisplay
|
567
|
574
|
{
|
568
|
575
|
PropertyReference = item.PropertyRef,
|
569
|
|
- DateAvailable = item.DateAvailable,
|
|
576
|
+ DateAvailable = item.DateAvailable,
|
570
|
577
|
Id = item.Id,
|
571
|
578
|
ShortDescription = item.ShortDescription,
|
572
|
579
|
IsSale = item.IsSale,
|
|
@@ -686,8 +693,8 @@ namespace UnivateProperties_API.Repository.Properties
|
686
|
693
|
break;
|
687
|
694
|
}
|
688
|
695
|
|
689
|
|
- List<Property> props = dBContext.Properties.Include("PropertyType").Where(x => x.Published
|
690
|
|
- && x.PropertyType.UsageType == type
|
|
696
|
+ List<Property> props = dBContext.Properties.Include("PropertyType").Where(x => x.Published
|
|
697
|
+ && x.PropertyType.UsageType == type
|
691
|
698
|
&& (x.CutOffDisplayDate == DateTime.MinValue || x.CutOffDisplayDate.Date > DateTime.Now.Date)).OrderByDescending(x => x.DatePublished).Take(4).ToList();
|
692
|
699
|
return GetDisplayDetails(props);
|
693
|
700
|
}
|
|
@@ -724,7 +731,7 @@ namespace UnivateProperties_API.Repository.Properties
|
724
|
731
|
}
|
725
|
732
|
|
726
|
733
|
public List<PropertyList> GetPropertyList()
|
727
|
|
- {
|
|
734
|
+ {
|
728
|
735
|
return SetPropertyList(dBContext.Properties.Where(x => x.Published).ToList());
|
729
|
736
|
}
|
730
|
737
|
|
|
@@ -774,7 +781,7 @@ namespace UnivateProperties_API.Repository.Properties
|
774
|
781
|
|
775
|
782
|
public void Insert(PropertyContainer items)
|
776
|
783
|
{
|
777
|
|
- Property property = new Property();
|
|
784
|
+ Property property = new Property();
|
778
|
785
|
PropertyType pt = dBContext.PropertyTypes.Find(items.PropertyTypeId);
|
779
|
786
|
if (pt != null)
|
780
|
787
|
{
|
|
@@ -809,9 +816,9 @@ namespace UnivateProperties_API.Repository.Properties
|
809
|
816
|
items.PropertyUserFields = null;
|
810
|
817
|
|
811
|
818
|
var individual = dBContext.Individuals.Where(i => i.UserId == items.UserId).FirstOrDefault();
|
812
|
|
- var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
|
|
819
|
+ var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
|
813
|
820
|
|
814
|
|
- foreach( string prop in property.GetAllProperties())
|
|
821
|
+ foreach (string prop in property.GetAllProperties())
|
815
|
822
|
{
|
816
|
823
|
if (prop != "Item" && prop != "Display")
|
817
|
824
|
property[prop] = items[prop];
|
|
@@ -823,9 +830,9 @@ namespace UnivateProperties_API.Repository.Properties
|
823
|
830
|
{
|
824
|
831
|
property.AgencyId = agent.AgencyId;
|
825
|
832
|
property.AgentId = agent.Id;
|
826
|
|
- }
|
|
833
|
+ }
|
827
|
834
|
|
828
|
|
- if (property.IsSale)
|
|
835
|
+ if (property.IsSale)
|
829
|
836
|
property.StatusId = dBContext.Status.Where(s => s.Description == "For Sale" && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
830
|
837
|
else
|
831
|
838
|
property.StatusId = dBContext.Status.Where(s => s.Description == "For Rent" && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
|
@@ -836,19 +843,29 @@ namespace UnivateProperties_API.Repository.Properties
|
836
|
843
|
if (images != null)
|
837
|
844
|
{
|
838
|
845
|
bool saveFiles = false;
|
|
846
|
+ var nextPropID = dBContext.GetMaxID("Properties") + 1;
|
839
|
847
|
var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
|
840
|
848
|
if (!string.IsNullOrEmpty(loc))
|
841
|
849
|
{
|
842
|
850
|
saveFiles = true;
|
843
|
|
- loc += string.Format("\\{0}", property.Id);
|
844
|
|
- if (Directory.Exists(loc))
|
|
851
|
+ if (loc.EndsWith("\\"))
|
|
852
|
+ {
|
|
853
|
+ loc = loc.Substring(0, loc.Length - 1);
|
|
854
|
+ }
|
|
855
|
+ loc += string.Format("\\{0}", nextPropID);
|
|
856
|
+ if (!Directory.Exists(loc))
|
845
|
857
|
{
|
846
|
858
|
Directory.CreateDirectory(loc);
|
847
|
859
|
}
|
848
|
860
|
}
|
849
|
861
|
|
850
|
862
|
property.PropertyImages = new List<PropertyImage>();
|
851
|
|
- var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
|
|
863
|
+ var lastID = 0;
|
|
864
|
+ if (dBContext.PropertyImages.Count() == 0)
|
|
865
|
+ lastID = 1;
|
|
866
|
+ else
|
|
867
|
+ lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
|
|
868
|
+
|
852
|
869
|
foreach (PropertyImage image in images)
|
853
|
870
|
{
|
854
|
871
|
image.PropertyId = property.Id;
|
|
@@ -863,7 +880,7 @@ namespace UnivateProperties_API.Repository.Properties
|
863
|
880
|
}
|
864
|
881
|
|
865
|
882
|
if (fields != null)
|
866
|
|
- {
|
|
883
|
+ {
|
867
|
884
|
property.PropertyUserFields = new List<PropertyUserField>();
|
868
|
885
|
foreach (PropertyUserField field in fields)
|
869
|
886
|
{
|
|
@@ -875,7 +892,7 @@ namespace UnivateProperties_API.Repository.Properties
|
875
|
892
|
dBContext.Properties.Add(property);
|
876
|
893
|
Save();
|
877
|
894
|
|
878
|
|
- items.Id = property.Id;
|
|
895
|
+ items.Id = property.Id;
|
879
|
896
|
}
|
880
|
897
|
|
881
|
898
|
public bool MayEdit(int id)
|
|
@@ -907,7 +924,7 @@ namespace UnivateProperties_API.Repository.Properties
|
907
|
924
|
}
|
908
|
925
|
|
909
|
926
|
foreach (PropertyImage image in Images)
|
910
|
|
- {
|
|
927
|
+ {
|
911
|
928
|
image.PropertyId = propertyID;
|
912
|
929
|
if (saveFiles)
|
913
|
930
|
{
|
|
@@ -989,7 +1006,7 @@ namespace UnivateProperties_API.Repository.Properties
|
989
|
1006
|
IsPublished = prop.Published,
|
990
|
1007
|
Type = prop.PropertyType.UsageType.ToString()
|
991
|
1008
|
};
|
992
|
|
-
|
|
1009
|
+
|
993
|
1010
|
if (prop.StatusId != null)
|
994
|
1011
|
{
|
995
|
1012
|
propAdmin.Status = dBContext.Status.Where(s => s.Id == prop.StatusId).FirstOrDefault()?.Description;
|