Lene Scholtz 5 年之前
父節點
當前提交
54e31a158f

+ 4
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs 查看文件

32
         public string DisplayImage { get; set; }
32
         public string DisplayImage { get; set; }
33
         public decimal Price { get; set; }        
33
         public decimal Price { get; set; }        
34
         public DateTime DateCreated { get; set; }
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 查看文件

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

+ 5
- 2
UnivateProperties_API/Containers/Property/PropertySearch.cs 查看文件

1
-using System.Collections.Generic;
1
+using System;
2
+using System.Collections.Generic;
2
 
3
 
3
 namespace UnivateProperties_API.Containers.Property
4
 namespace UnivateProperties_API.Containers.Property
4
 {
5
 {
15
         public string Suburb { get; set; }
16
         public string Suburb { get; set; }
16
         public decimal MinPrice { get; set; }
17
         public decimal MinPrice { get; set; }
17
         public decimal MaxPrice { get; set; }
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 查看文件

1
 using Microsoft.AspNetCore.Mvc;
1
 using Microsoft.AspNetCore.Mvc;
2
+using System;
2
 using System.Collections.Generic;
3
 using System.Collections.Generic;
3
 using System.Linq;
4
 using System.Linq;
4
 using System.Transactions;
5
 using System.Transactions;
65
         }
66
         }
66
 
67
 
67
         //Will need to come out. Post search not working......:(
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
             var search = new PropertySearch()
72
             var search = new PropertySearch()
72
             {
73
             {
79
                 City = city,
80
                 City = city,
80
                 Suburb = suburb,
81
                 Suburb = suburb,
81
                 MinPrice = minPrice,
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
             return new OkObjectResult(_Repo.GetDisplay(search));
92
             return new OkObjectResult(_Repo.GetDisplay(search));
86
         }
93
         }

+ 7
- 5
UnivateProperties_API/Model/Properties/Property.cs 查看文件

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

+ 3
- 2
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs 查看文件

19
         }
19
         }
20
         public List<PropertyImage> Get(Func<PropertyImage, bool> where)
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
             foreach (PropertyImage img in images)
24
             foreach (PropertyImage img in images)
25
             {
25
             {
49
         {
49
         {
50
             var images = (from p in dBContext.PropertyImages
50
             var images = (from p in dBContext.PropertyImages
51
                           where p.PropertyId == PropertyId
51
                           where p.PropertyId == PropertyId
52
-                          select p.Image).ToList();
52
+                          orderby p.IsDefault descending
53
+                          select p.Image).ToList();            
53
 
54
 
54
             List<string> formated = new List<string>();
55
             List<string> formated = new List<string>();
55
 
56
 

+ 48
- 10
UnivateProperties_API/Repository/Properties/PropertyRepository.cs 查看文件

1
-using Microsoft.EntityFrameworkCore;
1
+#define ReturnImages
2
+//#undef ReturnImages  //Comment out to return images
3
+
4
+using Microsoft.EntityFrameworkCore;
2
 using Newtonsoft.Json;
5
 using Newtonsoft.Json;
3
 using System;
6
 using System;
4
 using System.Collections.Generic;
7
 using System.Collections.Generic;
104
 
107
 
105
                         foreach (var val in groupFields)
108
                         foreach (var val in groupFields)
106
                         {
109
                         {
107
-                            var irem = new PropertyDetail()
110
+                            var item = new PropertyDetail()
108
                             {
111
                             {
109
                                 Name = val.FieldName,
112
                                 Name = val.FieldName,
110
                                 Description = val.Description
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
                             else
122
                             else
120
-                                irem.Value = val.Value;
123
+                                item.Value = val.Value;
121
                         }
124
                         }
122
 
125
 
123
                         property.DisplayData.Add(detailGroup);
126
                         property.DisplayData.Add(detailGroup);
329
         
332
         
330
         public List<PropertyDisplay> GetDisplay(PropertySearch search)
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
             SearchObject obj = new SearchObject()
341
             SearchObject obj = new SearchObject()
333
             {
342
             {
334
                 UserName = search.UserName,
343
                 UserName = search.UserName,
359
             else
368
             else
360
             {
369
             {
361
                 List<Property> props;
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
                 PropertyUsageType uType = PropertyUsageType.Both;
379
                 PropertyUsageType uType = PropertyUsageType.Both;
363
 
380
 
364
                 if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
381
                 if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
380
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
397
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
381
                 {
398
                 {
382
                     if (search.SalesType.ToUpper() == "SALE")
399
                     if (search.SalesType.ToUpper() == "SALE")
400
+                    {
383
                         props = props.Where(p => p.IsSale).ToList();
401
                         props = props.Where(p => p.IsSale).ToList();
402
+                        search.AvailableFrom = DateTime.MinValue; //Sales do not have an available from date. 
403
+                    }
384
                     else
404
                     else
385
                         props = props.Where(p => !p.IsSale).ToList();
405
                         props = props.Where(p => !p.IsSale).ToList();
386
 
406
 
453
                     SaveLog(obj);
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
                 return GetDisplayDetails(props);
485
                 return GetDisplayDetails(props);
457
             }
486
             }
458
         }        
487
         }        
472
         {
501
         {
473
             var properties = new List<PropertyDisplay>();
502
             var properties = new List<PropertyDisplay>();
474
             foreach (var item in props)
503
             foreach (var item in props)
475
-            {
504
+            {                
476
                 PropertyDisplay display = new PropertyDisplay
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
                     Id = item.Id,
509
                     Id = item.Id,
479
                     ShortDescription = item.ShortDescription,
510
                     ShortDescription = item.ShortDescription,
480
                     IsSale = item.IsSale,
511
                     IsSale = item.IsSale,
516
                     DateCreated = item.Created,
547
                     DateCreated = item.Created,
517
                     PropertyUsageType = (from p in dBContext.PropertyTypes
548
                     PropertyUsageType = (from p in dBContext.PropertyTypes
518
                                          where p.Id == item.PropertyTypeId
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
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
554
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
529
                     display.Area = display.Area.Substring(0, display.Area.Length - 1) + "<sup>" + display.Area.Last() + "</sup>";
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
                 properties.Add(display);
569
                 properties.Add(display);
533
             }
570
             }
534
 
571
 
588
                     Price = string.Format("R {0:n}", p.Price),
625
                     Price = string.Format("R {0:n}", p.Price),
589
                     Publish = p.Published.ToString(),
626
                     Publish = p.Published.ToString(),
590
                     Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description,
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
                 prop.Size = (from u in dBContext.PropertyUserFields
632
                 prop.Size = (from u in dBContext.PropertyUserFields

Loading…
取消
儲存