Kaynağa Gözat

Property and Search changes

master
George Williams 5 yıl önce
ebeveyn
işleme
48a935a7af

+ 4
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Dosyayı Görüntüle

@@ -32,6 +32,9 @@ namespace UnivateProperties_API.Containers.Property
32 32
         public string DisplayImage { get; set; }
33 33
         public decimal Price { get; set; }        
34 34
         public DateTime DateCreated { get; set; }
35
-        #endregion 
35
+        public DateTime DateAvailable { get; set; }
36
+        public string Available { get; set; }
37
+        public bool HasPendingOffer { get; set; }
38
+        #endregion
36 39
     }
37 40
 }

+ 4
- 1
UnivateProperties_API/Containers/Property/PropertyList.cs Dosyayı Görüntüle

@@ -1,10 +1,13 @@
1
-namespace UnivateProperties_API.Containers.Property
1
+using System;
2
+
3
+namespace UnivateProperties_API.Containers.Property
2 4
 {
3 5
     public class PropertyList
4 6
     {
5 7
         #region Properties
6 8
         public string Name { get; set; }
7 9
         public int Id { get; set; }
10
+        public DateTime DateAvailable { get; set; }
8 11
         public string Size { get; set; }
9 12
         public string Price { get; set; }
10 13
         public string UsageType { get; set;  }

+ 5
- 2
UnivateProperties_API/Containers/Property/PropertySearch.cs Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1
-using System.Collections.Generic;
1
+using System;
2
+using System.Collections.Generic;
2 3
 
3 4
 namespace UnivateProperties_API.Containers.Property
4 5
 {
@@ -15,6 +16,8 @@ namespace UnivateProperties_API.Containers.Property
15 16
         public string Suburb { get; set; }
16 17
         public decimal MinPrice { get; set; }
17 18
         public decimal MaxPrice { get; set; }
18
-        #endregion 
19
+        public DateTime AvailableFrom { get; set; }
20
+        public int PropertyId { get; set; }
21
+        #endregion
19 22
     }
20 23
 }

+ 11
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1 1
 using Microsoft.AspNetCore.Mvc;
2
+using System;
2 3
 using System.Collections.Generic;
3 4
 using System.Linq;
4 5
 using System.Transactions;
@@ -65,8 +66,8 @@ namespace UnivateProperties_API.Controllers.Properties
65 66
         }
66 67
 
67 68
         //Will need to come out. Post search not working......:(
68
-        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
69
-        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
69
+        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}/{availableFrom}/{propertyId}")]
70
+        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice, string availableFrom, int propertyId)
70 71
         {
71 72
             var search = new PropertySearch()
72 73
             {
@@ -79,8 +80,14 @@ namespace UnivateProperties_API.Controllers.Properties
79 80
                 City = city,
80 81
                 Suburb = suburb,
81 82
                 MinPrice = minPrice,
82
-                MaxPrice = maxPrice
83
-            };
83
+                MaxPrice = maxPrice,
84
+                PropertyId = propertyId
85
+            };            
86
+
87
+            if (availableFrom == "undefined")
88
+                search.AvailableFrom = DateTime.MinValue;
89
+            else
90
+                search.AvailableFrom = DateTime.Parse(availableFrom);
84 91
 
85 92
             return new OkObjectResult(_Repo.GetDisplay(search));
86 93
         }

+ 7
- 5
UnivateProperties_API/Model/Properties/Property.cs Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1
-using System.Collections.Generic;
1
+using System;
2
+using System.Collections.Generic;
2 3
 using System.ComponentModel.DataAnnotations.Schema;
3 4
 using UnivateProperties_API.Containers.Property;
4 5
 using UnivateProperties_API.Model.ProcessFlow;
@@ -9,13 +10,13 @@ using UnivateProperties_API.Model.Users;
9 10
 namespace UnivateProperties_API.Model.Properties
10 11
 {
11 12
     public class Property : BaseEntity
12
-    {        
13
+    {
13 14
         #region Properties        
14
-        [ForeignKey("PropertyType")]        
15
+        [ForeignKey("PropertyType")]
15 16
         public int PropertyTypeId { get; set; }
16 17
         public string PropertyName { get; set; }
17 18
         public string Unit { get; set; }
18
-        public decimal OperationalCosts { get; set; }           
19
+        public decimal OperationalCosts { get; set; }
19 20
         public decimal Price { get; set; }
20 21
         public string PricePer { get; set; }
21 22
         public bool IsSale { get; set; }
@@ -37,7 +38,8 @@ namespace UnivateProperties_API.Model.Properties
37 38
         [ForeignKey("Agent")]
38 39
         public int? AgentId { get; set; }
39 40
         [ForeignKey("Agency")]
40
-        public int? AgencyId { get; set; }        
41
+        public int? AgencyId { get; set; }
42
+        public DateTime DateAvailable { get; set; }
41 43
 
42 44
         public virtual PropertyType PropertyType { get; set; }
43 45
         public virtual Province Province { get; set; }

+ 3
- 2
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs Dosyayı Görüntüle

@@ -19,7 +19,7 @@ namespace UnivateProperties_API.Repository.Properties
19 19
         }
20 20
         public List<PropertyImage> Get(Func<PropertyImage, bool> where)
21 21
         {
22
-            var images = dBContext.PropertyImages.Where(where).ToList();
22
+            var images = dBContext.PropertyImages.Where(where).OrderByDescending(i => i.IsDefault).ThenBy(i => i.Id).ToList();
23 23
 
24 24
             foreach (PropertyImage img in images)
25 25
             {
@@ -49,7 +49,8 @@ namespace UnivateProperties_API.Repository.Properties
49 49
         {
50 50
             var images = (from p in dBContext.PropertyImages
51 51
                           where p.PropertyId == PropertyId
52
-                          select p.Image).ToList();
52
+                          orderby p.IsDefault descending
53
+                          select p.Image).ToList();            
53 54
 
54 55
             List<string> formated = new List<string>();
55 56
 

+ 48
- 10
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Dosyayı Görüntüle

@@ -1,4 +1,7 @@
1
-using Microsoft.EntityFrameworkCore;
1
+#define ReturnImages
2
+//#undef ReturnImages  //Comment out to return images
3
+
4
+using Microsoft.EntityFrameworkCore;
2 5
 using Newtonsoft.Json;
3 6
 using System;
4 7
 using System.Collections.Generic;
@@ -104,20 +107,20 @@ namespace UnivateProperties_API.Repository.Properties
104 107
 
105 108
                         foreach (var val in groupFields)
106 109
                         {
107
-                            var irem = new PropertyDetail()
110
+                            var item = new PropertyDetail()
108 111
                             {
109 112
                                 Name = val.FieldName,
110 113
                                 Description = val.Description
111 114
                             };
112 115
 
113
-                            detailGroup.Values.Add(irem);
116
+                            detailGroup.Values.Add(item);
114 117
 
115
-                            if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
118
+                            if (!string.IsNullOrEmpty(val.Value) && (val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
116 119
                             {
117
-                                irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
120
+                                item.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
118 121
                             }
119 122
                             else
120
-                                irem.Value = val.Value;
123
+                                item.Value = val.Value;
121 124
                         }
122 125
 
123 126
                         property.DisplayData.Add(detailGroup);
@@ -329,6 +332,12 @@ namespace UnivateProperties_API.Repository.Properties
329 332
         
330 333
         public List<PropertyDisplay> GetDisplay(PropertySearch search)
331 334
         {
335
+            //return GetDisplayDetails(dBContext.Properties.ToList());
336
+
337
+            //StreamWriter SW = new StreamWriter(@"c:\temp\SearchData.txt", true);
338
+            //SW.WriteLine(string.Format("{0:yyyy-MM-dd hh:mm:ss} - {1}", DateTime.Now, JsonConvert.SerializeObject(search)));
339
+            //SW.Close();
340
+
332 341
             SearchObject obj = new SearchObject()
333 342
             {
334 343
                 UserName = search.UserName,
@@ -359,6 +368,14 @@ namespace UnivateProperties_API.Repository.Properties
359 368
             else
360 369
             {
361 370
                 List<Property> props;
371
+
372
+                //Property ID search will override other searches. 
373
+                if (search.PropertyId > 0)
374
+                {
375
+                    props = dBContext.Properties.Where(p => p.Id == search.PropertyId).ToList();
376
+                    return GetDisplayDetails(props);
377
+                }
378
+
362 379
                 PropertyUsageType uType = PropertyUsageType.Both;
363 380
 
364 381
                 if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
@@ -380,7 +397,10 @@ namespace UnivateProperties_API.Repository.Properties
380 397
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
381 398
                 {
382 399
                     if (search.SalesType.ToUpper() == "SALE")
400
+                    {
383 401
                         props = props.Where(p => p.IsSale).ToList();
402
+                        search.AvailableFrom = DateTime.MinValue; //Sales do not have an available from date. 
403
+                    }
384 404
                     else
385 405
                         props = props.Where(p => !p.IsSale).ToList();
386 406
 
@@ -453,6 +473,15 @@ namespace UnivateProperties_API.Repository.Properties
453 473
                     SaveLog(obj);
454 474
                 }
455 475
 
476
+                if (search.AvailableFrom != DateTime.MinValue)
477
+                {
478
+                    props = props.Where(p => p.DateAvailable.Date >= search.AvailableFrom.Date).ToList();
479
+
480
+                    obj.Property = "AvailableFrom";
481
+                    obj.Value = search.AvailableFrom.ToString();
482
+                    SaveLog(obj);
483
+                }
484
+
456 485
                 return GetDisplayDetails(props);
457 486
             }
458 487
         }        
@@ -472,9 +501,11 @@ namespace UnivateProperties_API.Repository.Properties
472 501
         {
473 502
             var properties = new List<PropertyDisplay>();
474 503
             foreach (var item in props)
475
-            {
504
+            {                
476 505
                 PropertyDisplay display = new PropertyDisplay
477
-                {
506
+                {          
507
+                    DateAvailable = item.DateAvailable,
508
+                    Available = item.DateAvailable.Date > DateTime.Now.Date ? string.Format("Available form: {0: dd MMM yyyy}", item.DateAvailable) : "Available Now",
478 509
                     Id = item.Id,
479 510
                     ShortDescription = item.ShortDescription,
480 511
                     IsSale = item.IsSale,
@@ -516,7 +547,8 @@ namespace UnivateProperties_API.Repository.Properties
516 547
                     DateCreated = item.Created,
517 548
                     PropertyUsageType = (from p in dBContext.PropertyTypes
518 549
                                          where p.Id == item.PropertyTypeId
519
-                                         select p.UsageType.ToString()).FirstOrDefault()
550
+                                         select p.UsageType.ToString()).FirstOrDefault(),
551
+                    HasPendingOffer = !MayEdit(item.Id)
520 552
                 };
521 553
 
522 554
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
@@ -529,6 +561,11 @@ namespace UnivateProperties_API.Repository.Properties
529 561
                     display.Area = display.Area.Substring(0, display.Area.Length - 1) + "<sup>" + display.Area.Last() + "</sup>";
530 562
                 }
531 563
 
564
+                if (display.HasPendingOffer)
565
+                    display.Available = "Offer Pending";
566
+#if !ReturnImages
567
+                display.DisplayImage = "";
568
+#endif
532 569
                 properties.Add(display);
533 570
             }
534 571
 
@@ -588,7 +625,8 @@ namespace UnivateProperties_API.Repository.Properties
588 625
                     Price = string.Format("R {0:n}", p.Price),
589 626
                     Publish = p.Published.ToString(),
590 627
                     Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description,
591
-                    CarouselDescription = string.Format("{0}, {1} <br/>{2}", p.Suburb.Description, p.City.Description, p.AddressLine3)
628
+                    CarouselDescription = string.Format("{0}, {1} <br/>{2}", p.Suburb.Description, p.City.Description, p.AddressLine3),
629
+                    DateAvailable = p.DateAvailable
592 630
                 };
593 631
 
594 632
                 prop.Size = (from u in dBContext.PropertyUserFields

Loading…
İptal
Kaydet