|
@@ -1,15 +1,14 @@
|
1
|
1
|
using Microsoft.EntityFrameworkCore;
|
2
|
2
|
using Newtonsoft.Json;
|
3
|
3
|
using System;
|
4
|
|
-using System.IO;
|
5
|
4
|
using System.Collections.Generic;
|
|
5
|
+using System.IO;
|
6
|
6
|
using System.Linq;
|
7
|
7
|
using UnivateProperties_API.Containers.Property;
|
8
|
8
|
using UnivateProperties_API.Containers.Timeshare;
|
9
|
9
|
using UnivateProperties_API.Context;
|
10
|
10
|
using UnivateProperties_API.Model.Logging;
|
11
|
11
|
using UnivateProperties_API.Model.Properties;
|
12
|
|
-using System.Drawing;
|
13
|
12
|
|
14
|
13
|
namespace UnivateProperties_API.Repository.Properties
|
15
|
14
|
{
|
|
@@ -40,12 +39,17 @@ namespace UnivateProperties_API.Repository.Properties
|
40
|
39
|
|
41
|
40
|
public Property GetDetailed(Func<Property, bool> first)
|
42
|
41
|
{
|
43
|
|
- var property = dBContext.Properties.Include("Status").FirstOrDefault(first);
|
|
42
|
+ throw new NotImplementedException();
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ public PropertyContainer GetDetailed(int id, bool detailed)
|
|
46
|
+ {
|
|
47
|
+ var property = dBContext.Properties.Include("Status").Where(p => p.Id == id).FirstOrDefault();
|
44
|
48
|
if (property != null)
|
45
|
49
|
{
|
46
|
|
- GetDetail(ref property);
|
|
50
|
+ return GetDetail(property, detailed);
|
47
|
51
|
}
|
48
|
|
- return property;
|
|
52
|
+ return null;
|
49
|
53
|
}
|
50
|
54
|
|
51
|
55
|
public List<Property> GetDetailedAll()
|
|
@@ -54,8 +58,8 @@ namespace UnivateProperties_API.Repository.Properties
|
54
|
58
|
return properties;
|
55
|
59
|
}
|
56
|
60
|
|
57
|
|
- private void GetDetail(ref Property property)
|
58
|
|
- {
|
|
61
|
+ private PropertyContainer GetDetail(Property property, bool detailed)
|
|
62
|
+ {
|
59
|
63
|
int propID = property.Id;
|
60
|
64
|
var propertyType = dBContext.PropertyTypes.Find(property.PropertyTypeId);
|
61
|
65
|
property.Province = dBContext.Provinces.Find(property.ProvinceId);
|
|
@@ -63,148 +67,90 @@ namespace UnivateProperties_API.Repository.Properties
|
63
|
67
|
property.Suburb = dBContext.Suburbs.Find(property.SuburbId);
|
64
|
68
|
property.DisplayData = new List<PropertyDetailGroup>();
|
65
|
69
|
|
66
|
|
- var groups = (from g in dBContext.UserDefinedGroups
|
67
|
|
- where g.UsageType == propertyType.UsageType
|
68
|
|
- || g.UsageType == PropertyUsageType.Both
|
69
|
|
- orderby g.Rank
|
70
|
|
- select g).ToList();
|
71
|
|
-
|
72
|
|
- foreach (UserDefinedGroup uGroup in groups)
|
|
70
|
+ if (detailed)
|
73
|
71
|
{
|
74
|
|
- var groupFields = (from f in dBContext.PropertyUserFields
|
75
|
|
- join uf in dBContext.UserDefinedFields on f.UserDefinedFieldId equals uf.Id
|
76
|
|
- join g in dBContext.UserDefinedGroups on uf.GroupId equals g.Id
|
77
|
|
- where f.PropertyId == propID
|
78
|
|
- && g.Id == uGroup.Id
|
79
|
|
- orderby g.Rank, uf.Rank
|
80
|
|
- select new { uf.FieldName, f.Value, f.Description }).ToList();
|
81
|
|
-
|
82
|
|
- if (groupFields.Count > 0)
|
83
|
|
- {
|
84
|
|
- PropertyDetailGroup detailGroup = new PropertyDetailGroup()
|
85
|
|
- {
|
86
|
|
- GroupName = uGroup.Description,
|
87
|
|
- Values = new List<PropertyDetail>()
|
88
|
|
- };
|
89
|
|
-
|
90
|
|
- if (uGroup.Description == "Property Overview")
|
91
|
|
- {
|
92
|
|
- detailGroup.Values.Add(new PropertyDetail()
|
93
|
|
- {
|
94
|
|
- Name = "Property Type",
|
95
|
|
- Value = property.PropertyType.Description
|
96
|
|
- });
|
97
|
|
- }
|
|
72
|
+ var groups = (from g in dBContext.UserDefinedGroups
|
|
73
|
+ where g.UsageType == propertyType.UsageType
|
|
74
|
+ || g.UsageType == PropertyUsageType.Both
|
|
75
|
+ orderby g.Rank
|
|
76
|
+ select g).ToList();
|
98
|
77
|
|
99
|
|
- foreach (var val in groupFields)
|
|
78
|
+ foreach (UserDefinedGroup uGroup in groups)
|
|
79
|
+ {
|
|
80
|
+ var groupFields = (from f in dBContext.PropertyUserFields
|
|
81
|
+ join uf in dBContext.UserDefinedFields on f.UserDefinedFieldId equals uf.Id
|
|
82
|
+ join g in dBContext.UserDefinedGroups on uf.GroupId equals g.Id
|
|
83
|
+ where f.PropertyId == propID
|
|
84
|
+ && g.Id == uGroup.Id
|
|
85
|
+ orderby g.Rank, uf.Rank
|
|
86
|
+ select new { uf.FieldName, f.Value, f.Description }).ToList();
|
|
87
|
+
|
|
88
|
+ if (groupFields.Count > 0)
|
100
|
89
|
{
|
101
|
|
- var irem = new PropertyDetail()
|
|
90
|
+ PropertyDetailGroup detailGroup = new PropertyDetailGroup()
|
102
|
91
|
{
|
103
|
|
- Name = val.FieldName,
|
104
|
|
- Description = val.Description
|
|
92
|
+ GroupName = uGroup.Description,
|
|
93
|
+ Values = new List<PropertyDetail>()
|
105
|
94
|
};
|
106
|
95
|
|
107
|
|
- detailGroup.Values.Add(irem);
|
|
96
|
+ if (uGroup.Description == "Property Overview")
|
|
97
|
+ {
|
|
98
|
+ detailGroup.Values.Add(new PropertyDetail()
|
|
99
|
+ {
|
|
100
|
+ Name = "Property Type",
|
|
101
|
+ Value = property.PropertyType.Description
|
|
102
|
+ });
|
|
103
|
+ }
|
108
|
104
|
|
109
|
|
- if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
|
|
105
|
+ foreach (var val in groupFields)
|
110
|
106
|
{
|
111
|
|
- irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
|
|
107
|
+ var irem = new PropertyDetail()
|
|
108
|
+ {
|
|
109
|
+ Name = val.FieldName,
|
|
110
|
+ Description = val.Description
|
|
111
|
+ };
|
|
112
|
+
|
|
113
|
+ detailGroup.Values.Add(irem);
|
|
114
|
+
|
|
115
|
+ if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
|
|
116
|
+ {
|
|
117
|
+ irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
|
|
118
|
+ }
|
|
119
|
+ else
|
|
120
|
+ irem.Value = val.Value;
|
112
|
121
|
}
|
113
|
|
- else
|
114
|
|
- irem.Value = val.Value;
|
115
|
|
- }
|
116
|
122
|
|
117
|
|
- property.DisplayData.Add(detailGroup);
|
|
123
|
+ property.DisplayData.Add(detailGroup);
|
|
124
|
+ }
|
118
|
125
|
}
|
119
|
126
|
}
|
120
|
|
- }
|
121
|
|
-
|
122
|
|
- public void Insert(Property item)
|
123
|
|
- {
|
124
|
|
- PropertyType pt = dBContext.PropertyTypes.Find(item.PropertyTypeId);
|
125
|
|
- if (pt != null)
|
|
127
|
+ else
|
126
|
128
|
{
|
127
|
|
- if (pt.UsageType == PropertyUsageType.Residential)
|
128
|
|
- {
|
129
|
|
- string type = dBContext.PropertyTypes.Find(item.PropertyTypeId).Description;
|
130
|
|
- if (item.PropertyUserFields.Count > 0)
|
131
|
|
- {
|
132
|
|
- string shortDesc = "{0} {1} {2}";
|
133
|
|
- UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
|
134
|
|
- var udValue = item.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
|
135
|
|
- if (udValue != null)
|
136
|
|
- item.ShortDescription = string.Format(shortDesc, udValue.Value, "Bedroom", pt.Description).Trim();
|
137
|
|
- else
|
138
|
|
- item.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
|
139
|
|
- }
|
140
|
|
- else
|
141
|
|
- {
|
142
|
|
- item.ShortDescription = type;
|
143
|
|
- }
|
144
|
|
- }
|
145
|
|
- else
|
146
|
|
- {
|
147
|
|
- item.ShortDescription = pt.Description;
|
148
|
|
- }
|
|
129
|
+ if (!string.IsNullOrEmpty(property.Video))
|
|
130
|
+ property.Video = string.Format("https://www.youtube.com/watch?v={0}", property.Video);
|
149
|
131
|
}
|
150
|
132
|
|
151
|
|
- var images = item.PropertyImages;
|
152
|
|
- var fields = item.PropertyUserFields;
|
|
133
|
+ var propertyDetails = new PropertyContainer();
|
153
|
134
|
|
154
|
|
- item.PropertyImages = null;
|
155
|
|
- item.PropertyUserFields = null;
|
156
|
|
-
|
157
|
|
- dBContext.Properties.Add(item);
|
158
|
|
- Save();
|
159
|
|
-
|
160
|
|
- if (images != null)
|
|
135
|
+ foreach (string prop in property.GetAllProperties())
|
161
|
136
|
{
|
162
|
|
- var lastID = (from p in dBContext.PropertyImages
|
163
|
|
- orderby p.Id descending
|
164
|
|
- select p.Id).FirstOrDefault();
|
|
137
|
+ if (prop != "Item")
|
|
138
|
+ propertyDetails[prop] = property[prop];
|
|
139
|
+ }
|
165
|
140
|
|
166
|
|
- bool saveFiles = false;
|
167
|
|
- var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
|
168
|
|
- if (!string.IsNullOrEmpty(loc))
|
169
|
|
- {
|
170
|
|
- saveFiles = true;
|
171
|
|
- loc += string.Format("\\{0}", item.Id);
|
172
|
|
- if (Directory.Exists(loc))
|
173
|
|
- {
|
174
|
|
- Directory.CreateDirectory(loc);
|
175
|
|
- }
|
176
|
|
- }
|
177
|
|
-
|
178
|
|
- foreach (PropertyImage image in images)
|
179
|
|
- {
|
180
|
|
- lastID++;
|
181
|
|
- image.Id = lastID;
|
182
|
|
- image.PropertyId = item.Id;
|
183
|
|
- if (saveFiles)
|
184
|
|
- {
|
185
|
|
- string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
|
186
|
|
- image.Image = path;
|
187
|
|
- }
|
188
|
|
- dBContext.PropertyImages.Add(image);
|
189
|
|
- Save();
|
190
|
|
- }
|
191
|
|
- }
|
|
141
|
+ propertyDetails.PropertyUsageType = propertyType.UsageType == PropertyUsageType.Commercial ? "Commercial" : "Residential";
|
192
|
142
|
|
193
|
|
- if (fields != null)
|
194
|
|
- {
|
195
|
|
- var lastID = (from p in dBContext.PropertyUserFields
|
196
|
|
- orderby p.Id descending
|
197
|
|
- select p.Id).FirstOrDefault();
|
|
143
|
+ if (property.OwnerId > 0)
|
|
144
|
+ propertyDetails.UserId = (dBContext.Individuals.Where(p => p.Id == property.OwnerId).FirstOrDefault().UserId).Value;
|
|
145
|
+ if (property.AgentId > 0)
|
|
146
|
+ propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
|
198
|
147
|
|
199
|
|
- foreach (PropertyUserField field in fields)
|
200
|
|
- {
|
201
|
|
- lastID++;
|
202
|
|
- field.Id = lastID;
|
203
|
|
- field.PropertyId = item.Id;
|
204
|
|
- dBContext.PropertyUserFields.Add(field);
|
205
|
|
- Save();
|
206
|
|
- }
|
207
|
|
- }
|
|
148
|
+ return propertyDetails;
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+ public void Insert(Property item)
|
|
152
|
+ {
|
|
153
|
+ throw new NotImplementedException();
|
208
|
154
|
}
|
209
|
155
|
|
210
|
156
|
public void Insert(IEnumerable<Property> items)
|
|
@@ -218,7 +164,7 @@ namespace UnivateProperties_API.Repository.Properties
|
218
|
164
|
|
219
|
165
|
public void Remove(Property item)
|
220
|
166
|
{
|
221
|
|
- dBContext.Properties.Remove(item);
|
|
167
|
+ item.IsDeleted = true;
|
222
|
168
|
Save();
|
223
|
169
|
}
|
224
|
170
|
|
|
@@ -226,7 +172,7 @@ namespace UnivateProperties_API.Repository.Properties
|
226
|
172
|
{
|
227
|
173
|
foreach (var item in items)
|
228
|
174
|
{
|
229
|
|
- dBContext.Properties.Remove(item);
|
|
175
|
+ item.IsDeleted = true;
|
230
|
176
|
}
|
231
|
177
|
Save();
|
232
|
178
|
}
|
|
@@ -248,10 +194,29 @@ namespace UnivateProperties_API.Repository.Properties
|
248
|
194
|
|
249
|
195
|
public void Update(Property item)
|
250
|
196
|
{
|
|
197
|
+ if (item.Video.StartsWith("http"))
|
|
198
|
+ item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
|
|
199
|
+
|
251
|
200
|
dBContext.Entry(item).State = EntityState.Modified;
|
252
|
201
|
Save();
|
253
|
202
|
}
|
254
|
203
|
|
|
204
|
+ public void Update(PropertyContainer item)
|
|
205
|
+ {
|
|
206
|
+ if (item.Video.StartsWith("http"))
|
|
207
|
+ item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
|
|
208
|
+
|
|
209
|
+ var property = new Property();
|
|
210
|
+ foreach (string prop in property.GetAllProperties())
|
|
211
|
+ {
|
|
212
|
+ if (prop != "Item")
|
|
213
|
+ property[prop] = item[prop];
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ dBContext.Entry(property).State = EntityState.Modified;
|
|
217
|
+ Save();
|
|
218
|
+ }
|
|
219
|
+
|
255
|
220
|
public List<PropertyDisplay> GetDisplay()
|
256
|
221
|
{
|
257
|
222
|
List<Property> props = GetAll();
|
|
@@ -461,7 +426,7 @@ namespace UnivateProperties_API.Repository.Properties
|
461
|
426
|
select p.UsageType.ToString()).FirstOrDefault()
|
462
|
427
|
};
|
463
|
428
|
|
464
|
|
- if (!display.DisplayImage.StartsWith("data:image"))
|
|
429
|
+ if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
|
465
|
430
|
{
|
466
|
431
|
display.DisplayImage = ImageFormatter.ImageToBase64(display.DisplayImage);
|
467
|
432
|
}
|
|
@@ -552,6 +517,115 @@ namespace UnivateProperties_API.Repository.Properties
|
552
|
517
|
{
|
553
|
518
|
// Not sure if properties need it
|
554
|
519
|
return 0;
|
555
|
|
- }
|
|
520
|
+ }
|
|
521
|
+
|
|
522
|
+ public void Insert(PropertyContainer items)
|
|
523
|
+ {
|
|
524
|
+ Property property = new Property();
|
|
525
|
+
|
|
526
|
+ PropertyType pt = dBContext.PropertyTypes.Find(items.PropertyTypeId);
|
|
527
|
+ if (pt != null)
|
|
528
|
+ {
|
|
529
|
+ if (pt.UsageType == PropertyUsageType.Residential)
|
|
530
|
+ {
|
|
531
|
+ string type = dBContext.PropertyTypes.Find(items.PropertyTypeId).Description;
|
|
532
|
+ if (items.PropertyUserFields.Count > 0)
|
|
533
|
+ {
|
|
534
|
+ string shortDesc = "{0} {1} {2}";
|
|
535
|
+ UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
|
|
536
|
+ var udValue = items.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
|
|
537
|
+ if (udValue != null)
|
|
538
|
+ items.ShortDescription = string.Format(shortDesc, udValue.Value, "Bedroom", pt.Description).Trim();
|
|
539
|
+ else
|
|
540
|
+ items.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
|
|
541
|
+ }
|
|
542
|
+ else
|
|
543
|
+ {
|
|
544
|
+ items.ShortDescription = type;
|
|
545
|
+ }
|
|
546
|
+ }
|
|
547
|
+ else
|
|
548
|
+ {
|
|
549
|
+ items.ShortDescription = pt.Description;
|
|
550
|
+ }
|
|
551
|
+ }
|
|
552
|
+
|
|
553
|
+ var images = items.PropertyImages;
|
|
554
|
+ var fields = items.PropertyUserFields;
|
|
555
|
+
|
|
556
|
+ items.PropertyImages = null;
|
|
557
|
+ items.PropertyUserFields = null;
|
|
558
|
+
|
|
559
|
+ var individual = dBContext.Individuals.Where(i => i.UserId == items.UserId).FirstOrDefault();
|
|
560
|
+ var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
|
|
561
|
+
|
|
562
|
+ foreach( string prop in property.GetAllProperties())
|
|
563
|
+ {
|
|
564
|
+ if (prop != "Item")
|
|
565
|
+ property[prop] = items[prop];
|
|
566
|
+ }
|
|
567
|
+
|
|
568
|
+ if (individual != null)
|
|
569
|
+ property.OwnerId = individual.Id;
|
|
570
|
+ if (agent != null)
|
|
571
|
+ {
|
|
572
|
+ property.AgencyId = agent.AgencyId;
|
|
573
|
+ property.AgentId = agent.Id;
|
|
574
|
+ }
|
|
575
|
+
|
|
576
|
+ property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
|
|
577
|
+
|
|
578
|
+ dBContext.Properties.Add(property);
|
|
579
|
+ Save();
|
|
580
|
+
|
|
581
|
+ if (images != null)
|
|
582
|
+ {
|
|
583
|
+ var lastID = (from p in dBContext.PropertyImages
|
|
584
|
+ orderby p.Id descending
|
|
585
|
+ select p.Id).FirstOrDefault();
|
|
586
|
+
|
|
587
|
+ bool saveFiles = false;
|
|
588
|
+ var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
|
|
589
|
+ if (!string.IsNullOrEmpty(loc))
|
|
590
|
+ {
|
|
591
|
+ saveFiles = true;
|
|
592
|
+ loc += string.Format("\\{0}", property.Id);
|
|
593
|
+ if (Directory.Exists(loc))
|
|
594
|
+ {
|
|
595
|
+ Directory.CreateDirectory(loc);
|
|
596
|
+ }
|
|
597
|
+ }
|
|
598
|
+
|
|
599
|
+ foreach (PropertyImage image in images)
|
|
600
|
+ {
|
|
601
|
+ lastID++;
|
|
602
|
+ image.Id = lastID;
|
|
603
|
+ image.PropertyId = property.Id;
|
|
604
|
+ if (saveFiles)
|
|
605
|
+ {
|
|
606
|
+ string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
|
|
607
|
+ image.Image = path;
|
|
608
|
+ }
|
|
609
|
+ dBContext.PropertyImages.Add(image);
|
|
610
|
+ Save();
|
|
611
|
+ }
|
|
612
|
+ }
|
|
613
|
+
|
|
614
|
+ if (fields != null)
|
|
615
|
+ {
|
|
616
|
+ var lastID = (from p in dBContext.PropertyUserFields
|
|
617
|
+ orderby p.Id descending
|
|
618
|
+ select p.Id).FirstOrDefault();
|
|
619
|
+
|
|
620
|
+ foreach (PropertyUserField field in fields)
|
|
621
|
+ {
|
|
622
|
+ lastID++;
|
|
623
|
+ field.Id = lastID;
|
|
624
|
+ field.PropertyId = property.Id;
|
|
625
|
+ dBContext.PropertyUserFields.Add(field);
|
|
626
|
+ Save();
|
|
627
|
+ }
|
|
628
|
+ }
|
|
629
|
+ }
|
556
|
630
|
}
|
557
|
631
|
}
|