Bläddra i källkod

Property Banners - changes

master
George Williams 4 år sedan
förälder
incheckning
68ac1ae321

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

@@ -13,6 +13,9 @@ namespace UnivateProperties_API.Containers.Property
13 13
         public string SalesTypeString { get; set; }
14 14
         public int UserId { get; set; }
15 15
         public string PropertyUsageType { get; set; }
16
+        public decimal OldPrice { get; set; }        
17
+        public string OldStatus { get; set; }
18
+        public string CutOffDisplayDateString { get; set; }
16 19
         public List<NewImage> NewImages { get; set; }
17 20
         public List<PropertyFieldGroup> PropertyOverviewFields { get; set; }
18 21
         public List<PropertyFieldGroup> PropertyFields { get; set; }

+ 2
- 2
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Visa fil

@@ -34,8 +34,8 @@ namespace UnivateProperties_API.Containers.Property
34 34
         public decimal Price { get; set; }        
35 35
         public DateTime DateCreated { get; set; }
36 36
         public DateTime DateAvailable { get; set; }
37
-        public string Available { get; set; }
38
-        public bool HasPendingOffer { get; set; }
37
+        public string DisplayColor { get; set; }
38
+        public string DisplayText { get; set; }
39 39
         #endregion
40 40
     }
41 41
 }

+ 1625
- 0
UnivateProperties_API/Migrations/20200917125427_priceredused.Designer.cs
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 23
- 0
UnivateProperties_API/Migrations/20200917125427_priceredused.cs Visa fil

@@ -0,0 +1,23 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class priceredused : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<bool>(
10
+                name: "PriceRedused",
11
+                table: "Properties",
12
+                nullable: false,
13
+                defaultValue: false);
14
+        }
15
+
16
+        protected override void Down(MigrationBuilder migrationBuilder)
17
+        {
18
+            migrationBuilder.DropColumn(
19
+                name: "PriceRedused",
20
+                table: "Properties");
21
+        }
22
+    }
23
+}

+ 1627
- 0
UnivateProperties_API/Migrations/20200918092143_Added Cutoff show date.Designer.cs
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 24
- 0
UnivateProperties_API/Migrations/20200918092143_Added Cutoff show date.cs Visa fil

@@ -0,0 +1,24 @@
1
+using System;
2
+using Microsoft.EntityFrameworkCore.Migrations;
3
+
4
+namespace UnivateProperties_API.Migrations
5
+{
6
+    public partial class AddedCutoffshowdate : Migration
7
+    {
8
+        protected override void Up(MigrationBuilder migrationBuilder)
9
+        {
10
+            migrationBuilder.AddColumn<DateTime>(
11
+                name: "CutOffDisplayDate",
12
+                table: "Properties",
13
+                nullable: false,
14
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
15
+        }
16
+
17
+        protected override void Down(MigrationBuilder migrationBuilder)
18
+        {
19
+            migrationBuilder.DropColumn(
20
+                name: "CutOffDisplayDate",
21
+                table: "Properties");
22
+        }
23
+    }
24
+}

+ 4
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs Visa fil

@@ -670,6 +670,8 @@ namespace UnivateProperties_API.Migrations
670 670
 
671 671
                     b.Property<DateTime>("Created");
672 672
 
673
+                    b.Property<DateTime>("CutOffDisplayDate");
674
+
673 675
                     b.Property<DateTime>("DateAvailable");
674 676
 
675 677
                     b.Property<DateTime>("DatePublished");
@@ -694,6 +696,8 @@ namespace UnivateProperties_API.Migrations
694 696
 
695 697
                     b.Property<string>("PricePer");
696 698
 
699
+                    b.Property<bool>("PriceRedused");
700
+
697 701
                     b.Property<string>("PropertCoords");
698 702
 
699 703
                     b.Property<string>("PropertyName");

+ 5
- 17
UnivateProperties_API/Model/Properties/Property.cs Visa fil

@@ -38,23 +38,10 @@ namespace UnivateProperties_API.Model.Properties
38 38
         public bool Published { get; set; }
39 39
         public DateTime DatePublished { get; set; }
40 40
         public string VirtualTour { get; set; }
41
+        public bool PriceRedused { get; set; }
41 42
         public string Video { get; set; }
42 43
         [ForeignKey("Status")]
43
-        public int? StatusId 
44
-        { 
45
-            get
46
-            {
47
-                return _StatusID;
48
-            }
49
-            set
50
-            {
51
-                _StatusID = value;
52
-                if (value != null)
53
-                {
54
-                    StatusDate = DateTime.Now;
55
-                }
56
-            }
57
-        }
44
+        public int? StatusId { get; set; }       
58 45
         [ForeignKey("Owner")]
59 46
         public int? OwnerId { get; set; }
60 47
         [ForeignKey("Agent")]
@@ -66,9 +53,10 @@ namespace UnivateProperties_API.Model.Properties
66 53
         public virtual PropertyType PropertyType { get; set; }            
67 54
         [NotMapped]
68 55
         public Status Status { get; set; }        
69
-        public virtual Individual Owner { get; set; }        
70
-        public virtual Agent Agent { get; set; }        
56
+        public virtual Individual Owner { get; set; }
57
+        public virtual Agent Agent { get; set; }
71 58
         public virtual Agency Agency { get; set; }
59
+        public DateTime CutOffDisplayDate { get; set; }        
72 60
 
73 61
         public ICollection<PropertyUserField> PropertyUserFields { get; set; }
74 62
         public ICollection<PropertyImage> PropertyImages { get; set; }

+ 76
- 22
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Visa fil

@@ -138,7 +138,8 @@ namespace UnivateProperties_API.Repository.Properties
138 138
 
139 139
             var propertyDetails = new PropertyContainer();
140 140
 
141
-            propertyDetails.SalesTypeString = property.IsSale ? "Sale" : "Rental";            
141
+            propertyDetails.SalesTypeString = property.IsSale ? "Sale" : "Rental";
142
+            propertyDetails.OldPrice = property.Price;
142 143
 
143 144
             foreach (string prop in property.GetAllProperties())
144 145
             {
@@ -147,7 +148,10 @@ namespace UnivateProperties_API.Repository.Properties
147 148
             }
148 149
 
149 150
             if (property.StatusId != null)
151
+            {
150 152
                 propertyDetails.StatusString = dBContext.Status.Where(s => s.Id == property.StatusId).FirstOrDefault()?.Description;
153
+                propertyDetails.OldStatus = propertyDetails.StatusString;
154
+            }
151 155
 
152 156
             propertyDetails.PropertyUsageType = propertyType.UsageType == PropertyUsageType.Commercial ? "Commercial" : "Residential";
153 157
 
@@ -157,7 +161,14 @@ namespace UnivateProperties_API.Repository.Properties
157 161
                 propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
158 162
 
159 163
             propertyDetails.NewImages = new List<NewImage>();
160
-            propertyDetails.DateAvailableString = string.Format("{0:yyyy-MM-dd}", property.DateAvailable);
164
+
165
+            if (property.DateAvailable != DateTime.MinValue)
166
+                propertyDetails.DateAvailableString = string.Format("{0:yyyy-MM-dd}", property.DateAvailable);
167
+
168
+            if (property.CutOffDisplayDate == DateTime.MinValue)
169
+                propertyDetails.CutOffDisplayDateString = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddMonths(1));
170
+            else
171
+                propertyDetails.CutOffDisplayDateString = string.Format("{0:yyyy-MM-dd}", property.CutOffDisplayDate);
161 172
 
162 173
             return propertyDetails;
163 174
         }
@@ -225,14 +236,34 @@ namespace UnivateProperties_API.Repository.Properties
225 236
             {
226 237
                 if (prop != "Item" && prop != "Display")
227 238
                     property[prop] = item[prop];
228
-            }
239
+            }            
229 240
 
230 241
             property.PropertyUserFields = null;
231 242
             property.PropertyImages = null;
232 243
 
244
+            if (item.Price < item.OldPrice)
245
+            {
246
+                property.PriceRedused = true;
247
+            }            
248
+
233 249
             if (!string.IsNullOrEmpty(item.StatusString))
234 250
             {
251
+                if (item.StatusString != item.OldStatus)
252
+                    property.StatusDate = DateTime.Now;
253
+
235 254
                 property.StatusId = dBContext.Status.Where(s => s.Description == item.StatusString && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
255
+                if ((item.StatusString.ToUpper() == "RENTED OUT" || item.StatusString.ToUpper() == "SOLD") && item.StatusString != item.OldStatus)  
256
+                {
257
+                    property.CutOffDisplayDate = DateTime.Now.AddMonths(1);
258
+                }
259
+                else
260
+                {
261
+                    property.CutOffDisplayDate = DateTime.MinValue;
262
+                }
263
+                if (item.StatusString.ToUpper() == "FOR SALE")
264
+                    property.IsSale = true;
265
+                if (item.StatusString.ToUpper() == "FOR RENT")
266
+                    property.IsSale = false;
236 267
             }
237 268
 
238 269
             if (!string.IsNullOrEmpty(item.DateAvailableString))
@@ -535,8 +566,7 @@ namespace UnivateProperties_API.Repository.Properties
535 566
                 PropertyDisplay display = new PropertyDisplay
536 567
                 {
537 568
                     PropertyReference = item.PropertyRef,
538
-                    DateAvailable = item.DateAvailable,
539
-                    Available = item.DateAvailable.Date > DateTime.Now.Date ? string.Format("Available form: {0: dd MMM yyyy}", item.DateAvailable) : "Available Now",
569
+                    DateAvailable = item.DateAvailable,                    
540 570
                     Id = item.Id,
541 571
                     ShortDescription = item.ShortDescription,
542 572
                     IsSale = item.IsSale,
@@ -572,29 +602,51 @@ namespace UnivateProperties_API.Repository.Properties
572 602
                     DateCreated = item.Created,
573 603
                     PropertyUsageType = (from p in dBContext.PropertyTypes
574 604
                                          where p.Id == item.PropertyTypeId
575
-                                         select p.UsageType.ToString()).FirstOrDefault(),
576
-                    HasPendingOffer = false
577
-                };                
605
+                                         select p.UsageType.ToString()).FirstOrDefault()
606
+                };
578 607
 
579
-                if (item.StatusId != null)
608
+                var status = dBContext.Status.Where(s => s.Id == item.StatusId).FirstOrDefault();
609
+                switch (status.Description.ToUpper())
580 610
                 {
581
-                    var status = dBContext.Status.Where(s => s.Id == item.StatusId).FirstOrDefault();
582
-                    if (status.Description.ToUpper() == "OFFER PENDING")
583
-                        display.HasPendingOffer = true;                    
611
+                    case "FOR RENT":
612
+                        if (item.DateAvailable < DateTime.Now)
613
+                        {
614
+                            display.DisplayText = "Available Now";
615
+                            display.DisplayColor = "green";
616
+                        }
617
+                        else
618
+                        {
619
+                            display.DisplayText = string.Format("Available From: {0:dd MMM yyyy}", item.DateAvailable);
620
+                            display.DisplayColor = "blue";
621
+                        }
622
+                        break;
623
+                    case "FOR SALE":
624
+                        if (item.PriceRedused)
625
+                        {
626
+                            display.DisplayText = "Price Redused";
627
+                            display.DisplayColor = "green";
628
+                        }
629
+                        else
630
+                        {
631
+                            display.DisplayText = "For Sale";
632
+                            display.DisplayColor = "blue";
633
+                        }
634
+                        break;
635
+                    case "OFFER PENDING":
636
+                        display.DisplayText = "Offer Pending";
637
+                        display.DisplayColor = "orange";
638
+                        break;
639
+                    default:
640
+                        display.DisplayText = status.Description;
641
+                        display.DisplayColor = "red";
642
+                        break;
643
+
584 644
                 }
585 645
 
586 646
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
587 647
                 {
588 648
                     display.DisplayImage = ImageFormatter.ImageToBase64(display.DisplayImage);
589 649
                 }
590
-
591
-                //if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))
592
-                //{
593
-                //    display.Area = display.Area.Substring(0, display.Area.Length - 1) + "<sup>" + display.Area.Last() + "</sup>";
594
-                //}
595
-
596
-                if (display.HasPendingOffer)
597
-                    display.Available = "Offer Pending";
598 650
 #if !ReturnImages
599 651
                 display.DisplayImage = "";
600 652
 #endif
@@ -617,7 +669,7 @@ namespace UnivateProperties_API.Repository.Properties
617 669
 
618 670
         public List<PropertyDisplay> GetLatestDisplay()
619 671
         {
620
-            List<Property> props = GetAll().Where(x => x.Published).OrderByDescending(x => x.DatePublished).Take(4).ToList();
672
+            List<Property> props = GetAll().Where(x => x.Published && (x.CutOffDisplayDate == DateTime.MinValue || x.CutOffDisplayDate.Date > DateTime.Now.Date)).OrderByDescending(x => x.DatePublished).Take(4).ToList();
621 673
             return GetDisplayDetails(props);
622 674
         }
623 675
 
@@ -634,7 +686,9 @@ namespace UnivateProperties_API.Repository.Properties
634 686
                     break;
635 687
             }
636 688
 
637
-            List<Property> props = dBContext.Properties.Include("PropertyType").Where(x => x.Published && x.PropertyType.UsageType == type).OrderByDescending(x => x.DatePublished).Take(4).ToList();
689
+            List<Property> props = dBContext.Properties.Include("PropertyType").Where(x => x.Published 
690
+                        && x.PropertyType.UsageType == type 
691
+                        && (x.CutOffDisplayDate == DateTime.MinValue || x.CutOffDisplayDate.Date > DateTime.Now.Date)).OrderByDescending(x => x.DatePublished).Take(4).ToList();
638 692
             return GetDisplayDetails(props);
639 693
         }
640 694
 

Laddar…
Avbryt
Spara