|
@@ -27,10 +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")
|
31
|
|
- .Include("Province")
|
32
|
|
- .Include("City")
|
33
|
|
- .Include("Suburb")
|
|
30
|
+ .Include("PropertyType")
|
34
|
31
|
.Where(where).ToList();
|
35
|
32
|
}
|
36
|
33
|
|
|
@@ -145,11 +142,16 @@ namespace UnivateProperties_API.Repository.Properties
|
145
|
142
|
|
146
|
143
|
var propertyDetails = new PropertyContainer();
|
147
|
144
|
|
|
145
|
+ propertyDetails.SalesTypeString = property.IsSale ? "Sale" : "Rental";
|
|
146
|
+
|
148
|
147
|
foreach (string prop in property.GetAllProperties())
|
149
|
148
|
{
|
150
|
149
|
if (prop != "Item" && prop != "Display")
|
151
|
150
|
propertyDetails[prop] = property[prop];
|
152
|
|
- }
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ if (property.StatusId != null)
|
|
154
|
+ propertyDetails.StatusString = dBContext.Status.Where(s => s.Id == property.StatusId).FirstOrDefault()?.Description;
|
153
|
155
|
|
154
|
156
|
propertyDetails.PropertyUsageType = propertyType.UsageType == PropertyUsageType.Commercial ? "Commercial" : "Residential";
|
155
|
157
|
|
|
@@ -209,7 +211,7 @@ namespace UnivateProperties_API.Repository.Properties
|
209
|
211
|
|
210
|
212
|
public void Update(Property item)
|
211
|
213
|
{
|
212
|
|
- if (item.Video.StartsWith("http"))
|
|
214
|
+ if (!string.IsNullOrEmpty(item.Video) && item.Video.StartsWith("http"))
|
213
|
215
|
item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
|
214
|
216
|
|
215
|
217
|
dBContext.Entry(item).State = EntityState.Modified;
|
|
@@ -218,7 +220,7 @@ namespace UnivateProperties_API.Repository.Properties
|
218
|
220
|
|
219
|
221
|
public void Update(PropertyContainer item)
|
220
|
222
|
{
|
221
|
|
- if (item.Video.StartsWith("http"))
|
|
223
|
+ if (!string.IsNullOrEmpty(item.Video) && item.Video.StartsWith("http"))
|
222
|
224
|
item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
|
223
|
225
|
|
224
|
226
|
var property = new Property();
|
|
@@ -231,84 +233,82 @@ namespace UnivateProperties_API.Repository.Properties
|
231
|
233
|
property.PropertyUserFields = null;
|
232
|
234
|
property.PropertyImages = null;
|
233
|
235
|
|
|
236
|
+ if (!string.IsNullOrEmpty(item.StatusString))
|
|
237
|
+ {
|
|
238
|
+ property.StatusId = dBContext.Status.Where(s => s.Description == item.StatusString && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
|
239
|
+ }
|
|
240
|
+
|
234
|
241
|
dBContext.Entry(property).State = EntityState.Modified;
|
235
|
242
|
|
236
|
243
|
#region Insert New UDFs
|
237
|
|
-
|
238
|
|
- foreach (var propGroup in item.PropertyOverviewFields)
|
|
244
|
+
|
|
245
|
+ foreach (var propGroup in item.PropertyFields)
|
239
|
246
|
{
|
240
|
247
|
foreach (var field in propGroup.Fields)
|
241
|
248
|
{
|
242
|
|
- if (field.ItemId == 0)
|
243
|
|
- {
|
244
|
|
- var propertyField = new PropertyUserField()
|
245
|
|
- {
|
246
|
|
- PropertyId = property.Id,
|
247
|
|
- UserDefinedFieldId = field.Id,
|
248
|
|
- Value = field.Value
|
249
|
|
- };
|
250
|
|
- dBContext.Add(propertyField);
|
251
|
|
- }
|
252
|
|
- else
|
|
249
|
+ if (field.Value != null)
|
253
|
250
|
{
|
254
|
|
- var propertyField = dBContext.PropertyUserFields.Where(p => p.Id == field.ItemId).FirstOrDefault();
|
255
|
|
- if (propertyField != null)
|
|
251
|
+ var propField = dBContext.PropertyUserFields.Where(u => u.PropertyId == property.Id && u.UserDefinedFieldId == field.Id).FirstOrDefault();
|
|
252
|
+ if (propField == null)
|
256
|
253
|
{
|
257
|
|
- if (string.IsNullOrEmpty(field.Value))
|
258
|
|
- propertyField.IsDeleted = true;
|
259
|
|
- else
|
260
|
|
- propertyField.Value = field.Value;
|
261
|
|
-
|
262
|
|
- dBContext.Entry(propertyField).State = EntityState.Modified;
|
|
254
|
+ propField = new PropertyUserField()
|
|
255
|
+ {
|
|
256
|
+ PropertyId = property.Id,
|
|
257
|
+ UserDefinedFieldId = field.Id,
|
|
258
|
+ Value = field.Value
|
|
259
|
+ };
|
|
260
|
+ dBContext.Add(propField);
|
263
|
261
|
}
|
264
|
|
- }
|
265
|
|
- }
|
266
|
|
- }
|
267
|
|
-
|
268
|
|
- foreach (var propGroup in item.PropertyFields)
|
269
|
|
- {
|
270
|
|
- foreach (var field in propGroup.Fields)
|
271
|
|
- {
|
272
|
|
- if (field.ItemId == 0)
|
273
|
|
- {
|
274
|
|
- var propertyField = new PropertyUserField()
|
275
|
|
- {
|
276
|
|
- PropertyId = property.Id,
|
277
|
|
- UserDefinedFieldId = field.Id,
|
278
|
|
- Value = field.Value
|
279
|
|
- };
|
280
|
|
- dBContext.Add(propertyField);
|
281
|
|
- }
|
282
|
|
- else
|
283
|
|
- {
|
284
|
|
- var propertyField = dBContext.PropertyUserFields.Where(p => p.Id == field.ItemId).FirstOrDefault();
|
285
|
|
- if (propertyField != null)
|
|
262
|
+ else
|
286
|
263
|
{
|
287
|
|
- if (string.IsNullOrEmpty(field.Value))
|
288
|
|
- propertyField.IsDeleted = true;
|
289
|
|
- else
|
290
|
|
- propertyField.Value = field.Value;
|
291
|
|
-
|
292
|
|
- dBContext.Entry(propertyField).State = EntityState.Modified;
|
|
264
|
+ propField.Value = field.Value;
|
|
265
|
+ dBContext.Entry(propField).State = EntityState.Modified;
|
293
|
266
|
}
|
294
|
|
- }
|
|
267
|
+ }
|
295
|
268
|
}
|
296
|
269
|
}
|
297
|
270
|
#endregion
|
298
|
271
|
|
299
|
272
|
#region Update Images
|
300
|
273
|
|
301
|
|
- if (item.PropertyImages != null)
|
|
274
|
+ if (item.NewImages != null)
|
302
|
275
|
{
|
303
|
|
- foreach (var image in item.PropertyImages)
|
|
276
|
+ var imgList = dBContext.PropertyImages.Where(p => p.PropertyId == property.Id).ToList();
|
|
277
|
+ foreach (var image in imgList)
|
|
278
|
+ {
|
|
279
|
+ dBContext.Remove(image);
|
|
280
|
+ }
|
|
281
|
+
|
|
282
|
+ bool saveFiles = false;
|
|
283
|
+ var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
|
|
284
|
+ if (!string.IsNullOrEmpty(loc))
|
|
285
|
+ {
|
|
286
|
+ saveFiles = true;
|
|
287
|
+ loc += string.Format("\\{0}", property.Id);
|
|
288
|
+ if (Directory.Exists(loc))
|
|
289
|
+ {
|
|
290
|
+ Directory.CreateDirectory(loc);
|
|
291
|
+ }
|
|
292
|
+ }
|
|
293
|
+
|
|
294
|
+ property.PropertyImages = new List<PropertyImage>();
|
|
295
|
+ var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
|
|
296
|
+ foreach (var image in item.NewImages)
|
304
|
297
|
{
|
305
|
|
- var propImage = dBContext.PropertyImages.Where(pi => pi.Id == image.Id).FirstOrDefault();
|
306
|
|
- if (propImage != null)
|
|
298
|
+ var propImage = new PropertyImage
|
|
299
|
+ {
|
|
300
|
+ PropertyId = property.Id,
|
|
301
|
+ Image = image.Image,
|
|
302
|
+ IsDefault = image.IsDefault
|
|
303
|
+ };
|
|
304
|
+
|
|
305
|
+ if (saveFiles)
|
307
|
306
|
{
|
308
|
|
- propImage.IsDefault = image.IsDefault;
|
309
|
|
- propImage.IsDeleted = image.IsDeleted;
|
310
|
|
- dBContext.Entry(propImage).State = EntityState.Modified;
|
|
307
|
+ string path = ImageFormatter.Base64ToImage(propImage.Image, loc, lastID.ToString());
|
|
308
|
+ propImage.Image = path;
|
311
|
309
|
}
|
|
310
|
+ property.PropertyImages.Add(propImage);
|
|
311
|
+ lastID++;
|
312
|
312
|
}
|
313
|
313
|
}
|
314
|
314
|
|
|
@@ -502,9 +502,7 @@ namespace UnivateProperties_API.Repository.Properties
|
502
|
502
|
private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
|
503
|
503
|
{
|
504
|
504
|
var properties = new List<PropertyDisplay>();
|
505
|
|
- //Removed publish check for now
|
506
|
|
- //props = props.Where(p => p.Published).ToList();
|
507
|
|
-
|
|
505
|
+ props = props.Where(p => p.Published).ToList();
|
508
|
506
|
foreach (var item in props)
|
509
|
507
|
{
|
510
|
508
|
PropertyDisplay display = new PropertyDisplay
|
|
@@ -584,9 +582,7 @@ namespace UnivateProperties_API.Repository.Properties
|
584
|
582
|
|
585
|
583
|
public List<PropertyDisplay> GetLatestDisplay()
|
586
|
584
|
{
|
587
|
|
- //Removed Published Check for now
|
588
|
|
- //List<Property> props = GetAll().Where(x => x.Published).OrderByDescending(x => x.DatePublished).Take(3).ToList();
|
589
|
|
- List<Property> props = GetAll().OrderByDescending(x => x.Created).Take(3).ToList();
|
|
585
|
+ List<Property> props = GetAll().Where(x => x.Published).OrderByDescending(x => x.DatePublished).Take(3).ToList();
|
590
|
586
|
return GetDisplayDetails(props);
|
591
|
587
|
}
|
592
|
588
|
|
|
@@ -622,10 +618,8 @@ namespace UnivateProperties_API.Repository.Properties
|
622
|
618
|
}
|
623
|
619
|
|
624
|
620
|
public List<PropertyList> GetPropertyList()
|
625
|
|
- {
|
626
|
|
- //Removed Published check for now
|
627
|
|
- //return SetPropertyList(dBContext.Properties.Where(x => x.Published).ToList());
|
628
|
|
- return SetPropertyList(dBContext.Properties.ToList());
|
|
621
|
+ {
|
|
622
|
+ return SetPropertyList(dBContext.Properties.Where(x => x.Published).ToList());
|
629
|
623
|
}
|
630
|
624
|
|
631
|
625
|
private List<PropertyList> SetPropertyList(List<Property> properties)
|
|
@@ -709,8 +703,7 @@ namespace UnivateProperties_API.Repository.Properties
|
709
|
703
|
items.PropertyUserFields = null;
|
710
|
704
|
|
711
|
705
|
var individual = dBContext.Individuals.Where(i => i.UserId == items.UserId).FirstOrDefault();
|
712
|
|
- var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
|
713
|
|
- var status = dBContext.Status.Where(a => a.Code == "P1").FirstOrDefault();
|
|
706
|
+ var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
|
714
|
707
|
|
715
|
708
|
foreach( string prop in property.GetAllProperties())
|
716
|
709
|
{
|
|
@@ -726,8 +719,10 @@ namespace UnivateProperties_API.Repository.Properties
|
726
|
719
|
property.AgentId = agent.Id;
|
727
|
720
|
}
|
728
|
721
|
|
729
|
|
- if (status != null)
|
730
|
|
- property.StatusId = status.Id;
|
|
722
|
+ if (property.IsSale)
|
|
723
|
+ property.StatusId = dBContext.Status.Where(s => s.Description == "For Sale" && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
|
724
|
+ else
|
|
725
|
+ property.StatusId = dBContext.Status.Where(s => s.Description == "For Rent" && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
731
|
726
|
|
732
|
727
|
if (!string.IsNullOrEmpty(property.Video))
|
733
|
728
|
property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
|
|
@@ -845,6 +840,59 @@ namespace UnivateProperties_API.Repository.Properties
|
845
|
840
|
property.DatePublished = DateTime.MinValue;
|
846
|
841
|
Update(property);
|
847
|
842
|
}
|
848
|
|
- }
|
|
843
|
+ }
|
|
844
|
+
|
|
845
|
+ public List<PropertyAdminContainer> GetAdminProperties(int UserId)
|
|
846
|
+ {
|
|
847
|
+ var user = dBContext.Users.Where(u => u.Id == UserId).FirstOrDefault();
|
|
848
|
+ List<PropertyAdminContainer> returnProps = new List<PropertyAdminContainer>();
|
|
849
|
+ List<Property> props;
|
|
850
|
+ if ((user.Role.ToUpper() == "SUPER ADMIN"))
|
|
851
|
+ {
|
|
852
|
+ props = dBContext.Properties.Include("Owner").Include("PropertyType").ToList();
|
|
853
|
+ }
|
|
854
|
+ else
|
|
855
|
+ {
|
|
856
|
+ var indiv = dBContext.Individuals.Where(i => i.UserId == user.Id).FirstOrDefault();
|
|
857
|
+ props = dBContext.Properties.Include("Owner").Include("PropertyType").Where(p => p.OwnerId == indiv.Id).ToList();
|
|
858
|
+ }
|
|
859
|
+
|
|
860
|
+ foreach (var prop in props)
|
|
861
|
+ {
|
|
862
|
+ var propAdmin = new PropertyAdminContainer()
|
|
863
|
+ {
|
|
864
|
+ Id = prop.Id,
|
|
865
|
+ Owner = prop.Owner?.FullName,
|
|
866
|
+ Property = prop.PropertyName,
|
|
867
|
+ Reference = prop.PropertyRef,
|
|
868
|
+ Unit = prop.Unit,
|
|
869
|
+ Size = (from u in dBContext.PropertyUserFields
|
|
870
|
+ join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
|
|
871
|
+ where u.PropertyId == prop.Id
|
|
872
|
+ && f.FieldName == "Floor Size"
|
|
873
|
+ select u.Value).FirstOrDefault(),
|
|
874
|
+ Price = prop.Price,
|
|
875
|
+ Region = prop.Province,
|
|
876
|
+ Town = prop.City,
|
|
877
|
+ Suburb = prop.Suburb,
|
|
878
|
+ IsPublished = prop.Published,
|
|
879
|
+ Type = prop.PropertyType.UsageType.ToString()
|
|
880
|
+ };
|
|
881
|
+
|
|
882
|
+ if (prop.StatusId != null)
|
|
883
|
+ {
|
|
884
|
+ propAdmin.Status = dBContext.Status.Where(s => s.Id == prop.StatusId).FirstOrDefault()?.Description;
|
|
885
|
+ }
|
|
886
|
+
|
|
887
|
+ returnProps.Add(propAdmin);
|
|
888
|
+ }
|
|
889
|
+
|
|
890
|
+ return returnProps;
|
|
891
|
+ }
|
|
892
|
+
|
|
893
|
+ public List<string> GetStatuses()
|
|
894
|
+ {
|
|
895
|
+ return dBContext.Status.Where(s => s.StatusType == StatusType.Property).Select(s => s.Description).ToList();
|
|
896
|
+ }
|
849
|
897
|
}
|
850
|
898
|
}
|