|  | @@ -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 |  
 |