|
@@ -33,7 +33,7 @@ namespace UnivateProperties_API.Repository.Properties
|
33
|
33
|
|
34
|
34
|
public List<Property> GetAll()
|
35
|
35
|
{
|
36
|
|
- var properties = dBContext.Properties.ToList();
|
|
36
|
+ var properties = dBContext.Properties.Include("PropertyType").ToList();
|
37
|
37
|
return properties;
|
38
|
38
|
}
|
39
|
39
|
|
|
@@ -161,6 +161,7 @@ namespace UnivateProperties_API.Repository.Properties
|
161
|
161
|
propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
|
162
|
162
|
|
163
|
163
|
propertyDetails.NewImages = new List<NewImage>();
|
|
164
|
+ propertyDetails.DateAvailableString = string.Format("{0:yyyy-MM-dd}", property.DateAvailable);
|
164
|
165
|
|
165
|
166
|
return propertyDetails;
|
166
|
167
|
}
|
|
@@ -238,10 +239,16 @@ namespace UnivateProperties_API.Repository.Properties
|
238
|
239
|
property.StatusId = dBContext.Status.Where(s => s.Description == item.StatusString && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
|
239
|
240
|
}
|
240
|
241
|
|
241
|
|
- dBContext.Entry(property).State = EntityState.Modified;
|
|
242
|
+ if (!string.IsNullOrEmpty(item.DateAvailableString))
|
|
243
|
+ {
|
|
244
|
+ property.DateAvailable = DateTime.Parse(item.DateAvailableString);
|
|
245
|
+ }
|
|
246
|
+
|
|
247
|
+ dBContext.Entry(property).State = EntityState.Modified;
|
|
248
|
+ Save();
|
242
|
249
|
|
243
|
250
|
#region Insert New UDFs
|
244
|
|
-
|
|
251
|
+
|
245
|
252
|
foreach (var propGroup in item.PropertyFields)
|
246
|
253
|
{
|
247
|
254
|
foreach (var field in propGroup.Fields)
|
|
@@ -258,27 +265,44 @@ namespace UnivateProperties_API.Repository.Properties
|
258
|
265
|
Value = field.Value
|
259
|
266
|
};
|
260
|
267
|
dBContext.Add(propField);
|
|
268
|
+ Save();
|
261
|
269
|
}
|
262
|
270
|
else
|
263
|
271
|
{
|
264
|
272
|
propField.Value = field.Value;
|
265
|
273
|
dBContext.Entry(propField).State = EntityState.Modified;
|
|
274
|
+ Save();
|
266
|
275
|
}
|
267
|
276
|
}
|
268
|
277
|
}
|
269
|
278
|
}
|
270
|
279
|
#endregion
|
271
|
280
|
|
272
|
|
- #region Update Images
|
|
281
|
+ #region Update Images
|
|
282
|
+ //property.PropertyImages = new List<PropertyImage>();
|
273
|
283
|
|
274
|
|
- if (item.NewImages != null)
|
|
284
|
+ if (item.PropertyImages != null)
|
275
|
285
|
{
|
276
|
|
- var imgList = dBContext.PropertyImages.Where(p => p.PropertyId == property.Id).ToList();
|
277
|
|
- foreach (var image in imgList)
|
|
286
|
+ foreach (var propImg in item.PropertyImages)
|
278
|
287
|
{
|
279
|
|
- dBContext.Remove(image);
|
|
288
|
+ var image = dBContext.PropertyImages.Where(pi => pi.Id == propImg.Id).FirstOrDefault();
|
|
289
|
+ if (image != null)
|
|
290
|
+ {
|
|
291
|
+ if (propImg.IsDeleted)
|
|
292
|
+ dBContext.PropertyImages.Remove(image);
|
|
293
|
+ else
|
|
294
|
+ {
|
|
295
|
+ image.IsDefault = propImg.IsDefault;
|
|
296
|
+ dBContext.Entry(image).State = EntityState.Modified;
|
|
297
|
+ Save();
|
|
298
|
+ //property.PropertyImages.Add(image);
|
|
299
|
+ }
|
|
300
|
+ }
|
280
|
301
|
}
|
|
302
|
+ }
|
281
|
303
|
|
|
304
|
+ if (item.NewImages != null)
|
|
305
|
+ {
|
282
|
306
|
bool saveFiles = false;
|
283
|
307
|
var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
|
284
|
308
|
if (!string.IsNullOrEmpty(loc))
|
|
@@ -291,7 +315,7 @@ namespace UnivateProperties_API.Repository.Properties
|
291
|
315
|
}
|
292
|
316
|
}
|
293
|
317
|
|
294
|
|
- property.PropertyImages = new List<PropertyImage>();
|
|
318
|
+
|
295
|
319
|
var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
|
296
|
320
|
foreach (var image in item.NewImages)
|
297
|
321
|
{
|
|
@@ -307,8 +331,15 @@ namespace UnivateProperties_API.Repository.Properties
|
307
|
331
|
string path = ImageFormatter.Base64ToImage(propImage.Image, loc, lastID.ToString());
|
308
|
332
|
propImage.Image = path;
|
309
|
333
|
}
|
310
|
|
- property.PropertyImages.Add(propImage);
|
311
|
|
- lastID++;
|
|
334
|
+
|
|
335
|
+ var exists = dBContext.PropertyImages.Where(pi => pi.Image == propImage.Image && pi.PropertyId == property.Id).FirstOrDefault();
|
|
336
|
+ if (exists == null)
|
|
337
|
+ {
|
|
338
|
+ //property.PropertyImages.Add(propImage);
|
|
339
|
+ dBContext.PropertyImages.Add(propImage);
|
|
340
|
+ Save();
|
|
341
|
+ lastID++;
|
|
342
|
+ }
|
312
|
343
|
}
|
313
|
344
|
}
|
314
|
345
|
|
|
@@ -507,6 +538,7 @@ namespace UnivateProperties_API.Repository.Properties
|
507
|
538
|
{
|
508
|
539
|
PropertyDisplay display = new PropertyDisplay
|
509
|
540
|
{
|
|
541
|
+ PropertyReference = item.PropertyRef,
|
510
|
542
|
DateAvailable = item.DateAvailable,
|
511
|
543
|
Available = item.DateAvailable.Date > DateTime.Now.Date ? string.Format("Available form: {0: dd MMM yyyy}", item.DateAvailable) : "Available Now",
|
512
|
544
|
Id = item.Id,
|
|
@@ -545,8 +577,15 @@ namespace UnivateProperties_API.Repository.Properties
|
545
|
577
|
PropertyUsageType = (from p in dBContext.PropertyTypes
|
546
|
578
|
where p.Id == item.PropertyTypeId
|
547
|
579
|
select p.UsageType.ToString()).FirstOrDefault(),
|
548
|
|
- HasPendingOffer = !MayEdit(item.Id)
|
549
|
|
- };
|
|
580
|
+ HasPendingOffer = false
|
|
581
|
+ };
|
|
582
|
+
|
|
583
|
+ if (item.StatusId != null)
|
|
584
|
+ {
|
|
585
|
+ var status = dBContext.Status.Where(s => s.Id == item.StatusId).FirstOrDefault();
|
|
586
|
+ if (status.Description.ToUpper() == "OFFER PENDING")
|
|
587
|
+ display.HasPendingOffer = true;
|
|
588
|
+ }
|
550
|
589
|
|
551
|
590
|
if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
|
552
|
591
|
{
|
|
@@ -586,6 +625,23 @@ namespace UnivateProperties_API.Repository.Properties
|
586
|
625
|
return GetDisplayDetails(props);
|
587
|
626
|
}
|
588
|
627
|
|
|
628
|
+ public List<PropertyDisplay> GetLatestDisplay(string PropertyType)
|
|
629
|
+ {
|
|
630
|
+ var type = PropertyUsageType.Both;
|
|
631
|
+ switch (PropertyType.ToUpper())
|
|
632
|
+ {
|
|
633
|
+ case "RESIDENTIAL":
|
|
634
|
+ type = PropertyUsageType.Residential;
|
|
635
|
+ break;
|
|
636
|
+ case "COMMERCIAL":
|
|
637
|
+ type = PropertyUsageType.Commercial;
|
|
638
|
+ break;
|
|
639
|
+ }
|
|
640
|
+
|
|
641
|
+ List<Property> props = dBContext.Properties.Include("PropertyType").Where(x => x.Published && x.PropertyType.UsageType == type).OrderByDescending(x => x.DatePublished).Take(4).ToList();
|
|
642
|
+ return GetDisplayDetails(props);
|
|
643
|
+ }
|
|
644
|
+
|
589
|
645
|
public List<PropertyList> GetPropertyList(int By)
|
590
|
646
|
{
|
591
|
647
|
List<Property> properties = new List<Property>();
|