Bläddra i källkod

Fixes made to the prop edit

master
George Williams 4 år sedan
förälder
incheckning
930c064f64

+ 1
- 0
UnivateProperties_API/Containers/Property/PropertyContainer.cs Visa fil

8
 {
8
 {
9
     public class PropertyContainer : Model.Properties.Property
9
     public class PropertyContainer : Model.Properties.Property
10
     {        
10
     {        
11
+        public string DateAvailableString { get; set; }
11
         public string StatusString { get; set; }
12
         public string StatusString { get; set; }
12
         public string SalesTypeString { get; set; }
13
         public string SalesTypeString { get; set; }
13
         public int UserId { get; set; }
14
         public int UserId { get; set; }

+ 1
- 0
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Visa fil

29
         public string Province { get; set; }
29
         public string Province { get; set; }
30
         public string City { get; set; }
30
         public string City { get; set; }
31
         public string Suburb { get; set; }
31
         public string Suburb { get; set; }
32
+        public string PropertyReference { get; set; }
32
         public string DisplayImage { get; set; }
33
         public string DisplayImage { get; set; }
33
         public decimal Price { get; set; }        
34
         public decimal Price { get; set; }        
34
         public DateTime DateCreated { get; set; }
35
         public DateTime DateCreated { get; set; }

+ 6
- 0
UnivateProperties_API/Controllers/Properties/PropertyController.cs Visa fil

45
             return new OkObjectResult(_Repo.GetLatestDisplay());
45
             return new OkObjectResult(_Repo.GetLatestDisplay());
46
         }
46
         }
47
 
47
 
48
+        [HttpGet("latestProperties/{type}")]
49
+        public IActionResult GetLatestProperties(string type)
50
+        {
51
+            return new OkObjectResult(_Repo.GetLatestDisplay(type));
52
+        }
53
+
48
         [HttpGet("GetPropertyList/{by}")]
54
         [HttpGet("GetPropertyList/{by}")]
49
         public IActionResult SearchBy(int by)
55
         public IActionResult SearchBy(int by)
50
         {
56
         {

+ 1
- 0
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs Visa fil

11
         List<PropertyDisplay> GetDisplay(Func<Property, bool> where);
11
         List<PropertyDisplay> GetDisplay(Func<Property, bool> where);
12
         List<PropertyDisplay> GetDisplay(PropertySearch search);        
12
         List<PropertyDisplay> GetDisplay(PropertySearch search);        
13
         List<PropertyDisplay> GetLatestDisplay();
13
         List<PropertyDisplay> GetLatestDisplay();
14
+        List<PropertyDisplay> GetLatestDisplay(string type);
14
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
15
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
15
         List<PropertyList> GetPropertyList(int By);
16
         List<PropertyList> GetPropertyList(int By);
16
         List<PropertyList> GetPropertyList();
17
         List<PropertyList> GetPropertyList();

+ 69
- 13
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Visa fil

33
 
33
 
34
         public List<Property> GetAll()
34
         public List<Property> GetAll()
35
         {
35
         {
36
-            var properties = dBContext.Properties.ToList();
36
+            var properties = dBContext.Properties.Include("PropertyType").ToList();
37
             return properties;
37
             return properties;
38
         }
38
         }
39
 
39
 
161
                 propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
161
                 propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
162
 
162
 
163
             propertyDetails.NewImages = new List<NewImage>();
163
             propertyDetails.NewImages = new List<NewImage>();
164
+            propertyDetails.DateAvailableString = string.Format("{0:yyyy-MM-dd}", property.DateAvailable);
164
 
165
 
165
             return propertyDetails;
166
             return propertyDetails;
166
         }
167
         }
238
                 property.StatusId = dBContext.Status.Where(s => s.Description == item.StatusString && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
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
             #region Insert New UDFs
250
             #region Insert New UDFs
244
-          
251
+
245
             foreach (var propGroup in item.PropertyFields)
252
             foreach (var propGroup in item.PropertyFields)
246
             {
253
             {
247
                 foreach (var field in propGroup.Fields)
254
                 foreach (var field in propGroup.Fields)
258
                                 Value = field.Value
265
                                 Value = field.Value
259
                             };
266
                             };
260
                             dBContext.Add(propField);
267
                             dBContext.Add(propField);
268
+                            Save();
261
                         }
269
                         }
262
                         else
270
                         else
263
                         {
271
                         {
264
                             propField.Value = field.Value;
272
                             propField.Value = field.Value;
265
                             dBContext.Entry(propField).State = EntityState.Modified;
273
                             dBContext.Entry(propField).State = EntityState.Modified;
274
+                            Save();
266
                         }
275
                         }
267
                     }                    
276
                     }                    
268
                 }
277
                 }
269
             }
278
             }
270
             #endregion
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
                 bool saveFiles = false;
306
                 bool saveFiles = false;
283
                 var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
307
                 var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
284
                 if (!string.IsNullOrEmpty(loc))
308
                 if (!string.IsNullOrEmpty(loc))
291
                     }
315
                     }
292
                 }
316
                 }
293
 
317
 
294
-                property.PropertyImages = new List<PropertyImage>();
318
+                             
295
                 var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
319
                 var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
296
                 foreach (var image in item.NewImages)
320
                 foreach (var image in item.NewImages)
297
                 {
321
                 {
307
                         string path = ImageFormatter.Base64ToImage(propImage.Image, loc, lastID.ToString());
331
                         string path = ImageFormatter.Base64ToImage(propImage.Image, loc, lastID.ToString());
308
                         propImage.Image = path;
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
             {
538
             {
508
                 PropertyDisplay display = new PropertyDisplay
539
                 PropertyDisplay display = new PropertyDisplay
509
                 {
540
                 {
541
+                    PropertyReference = item.PropertyRef,
510
                     DateAvailable = item.DateAvailable,
542
                     DateAvailable = item.DateAvailable,
511
                     Available = item.DateAvailable.Date > DateTime.Now.Date ? string.Format("Available form: {0: dd MMM yyyy}", item.DateAvailable) : "Available Now",
543
                     Available = item.DateAvailable.Date > DateTime.Now.Date ? string.Format("Available form: {0: dd MMM yyyy}", item.DateAvailable) : "Available Now",
512
                     Id = item.Id,
544
                     Id = item.Id,
545
                     PropertyUsageType = (from p in dBContext.PropertyTypes
577
                     PropertyUsageType = (from p in dBContext.PropertyTypes
546
                                          where p.Id == item.PropertyTypeId
578
                                          where p.Id == item.PropertyTypeId
547
                                          select p.UsageType.ToString()).FirstOrDefault(),
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
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
590
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
552
                 {
591
                 {
586
             return GetDisplayDetails(props);
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
         public List<PropertyList> GetPropertyList(int By)
645
         public List<PropertyList> GetPropertyList(int By)
590
         {
646
         {
591
             List<Property> properties = new List<Property>();
647
             List<Property> properties = new List<Property>();

Laddar…
Avbryt
Spara