public void EntryDeletion(DeleteEntryRequestModel request) { Entities.Property workingProperty = _propertyCRUD.ReadPropertyFromCaseID(request.CaseID); DeleteEntryResponseModel response = new DeleteEntryResponseModel(); _addressCRUD.DeleteAddress(workingProperty.PostalCode, workingProperty.AddressLine1); _propertyCRUD.DeleteProperty(workingProperty.PropertyID); _caseCRUD.DeleteCase(workingProperty.CaseID); response.Confirm = true; _deleteEntryOutput.ConfirmDeletion(response); }
/// <summary> /// Creates a new instance of a Property object, initializes it with the specified arguments. /// </summary> /// <param name="property"></param> public Property(Entities.Property property) { this.Id = property.Id; this.ProjectNumber = property.ProjectNumber; this.ClassificationId = property.ClassificationId; this.Classification = property.Classification?.Name; this.AgencyId = property.AgencyId; this.Agency = property.Agency?.ParentId != null ? property.Agency.Parent?.Name : property.Agency?.Name; this.AgencyCode = property.Agency?.ParentId != null ? property.Agency.Parent?.Code : property.Agency?.Code; this.SubAgency = property.Agency?.ParentId != null ? null : property.Agency?.Name; this.SubAgencyCode = property.Agency?.ParentId != null ? null : property.Agency?.Code; this.Description = property.Description; this.AddressId = property.AddressId; this.Address = property.Address != null ? $"{property.Address?.Address1} {property.Address?.Address2}".Trim() : null; this.City = property.Address?.City?.Name; this.Province = property.Address?.Province?.Name; this.Postal = property.Address?.Postal; this.Latitude = property.Latitude; this.Longitude = property.Longitude; this.IsSensitive = property.IsSensitive; }
/// <summary> /// Creates a new instance of a Property object, initializes it with the specified arguments. /// </summary> /// <param name="property"></param> public Property(Entities.Property property) { this.Id = property.Id; this.ProjectNumbers = property.ProjectNumbers; this.ClassificationId = property.ClassificationId; this.Classification = property.Classification?.Name; this.AgencyId = property.AgencyId; this.Agency = property.Agency?.ParentId.HasValue ?? false ? property.Agency.Parent?.Name : property.Agency?.Name; this.AgencyCode = property.Agency?.ParentId.HasValue ?? false ? property.Agency.Parent?.Code : property.Agency?.Code; this.SubAgency = property.Agency?.ParentId.HasValue ?? false ? property.Agency?.Name : null; this.SubAgencyCode = property.Agency?.ParentId.HasValue ?? false ? property.Agency?.Code : null; this.Name = property.Name; this.Description = property.Description; this.AddressId = property.AddressId; this.Address = property.Address != null ? $"{property.Address?.Address1} {property.Address?.Address2}".Trim() : null; this.AdministrativeArea = property.Address?.AdministrativeArea; this.Province = property.Address?.Province?.Name; this.Postal = property.Address?.Postal; this.Location = property.Location; this.Boundary = property.Boundary; this.IsSensitive = property.IsSensitive; }
/// <summary> /// Gets only the ids of the properties we've searched for /// </summary> public static IEnumerable <int> Search(REIQ.Enum.SearchType searchType, IEnumerable <string> propertyTypes, bool excludeUnderOffer, bool includeSurroundingSuburbs, bool onlyIfOpenHome, string keyword, int minPrice, int maxPrice, int numBedrooms, int numBathrooms, REIQ.Enum.SortOptions sortOption, int acId = 0) { // computed values from keyword Entities.Suburb suburb = null; // suburbing matching search keyword List <Entities.Suburb> suburbsList = new List <Entities.Suburb>(); // list of suburbs when search string contains several suburbs int?postcode = null; // exact postcode Entities.Property property = null; // exact property id entered into search string region = null; // keyword corresponds to a region List <string> regionsList = new List <string>(); //list of regions when query string contains several regions // several regions are selected if (keyword.Contains("::")) { foreach (var rg in keyword.Split(new string[] { "::" }, StringSplitOptions.None)) { regionsList.Add(rg); } } // several suburbs are selected else if (keyword.Contains("!!")) { foreach (var sb in keyword.Split(new string[] { "!!" }, StringSplitOptions.None)) { var match = Regex.Match(sb, "(.*), (4\\d{3})"); // in format "Suburb Name, 4XXX" if (match.Success) { var su = match.Groups[1].Value; var pc = Convert.ToInt32(match.Groups[2].Value); suburb = REIQ.Access.Suburb.Get(su, pc); //save search query into DB for stats if (suburb != null && !String.IsNullOrEmpty(suburb.name)) { Suburb.LogSuburbSearch(suburb); //remember found suburb suburbsList.Add(suburb); } } } } else { var match = Regex.Match(keyword, "(.*), (4\\d{3})"); // in format "Suburb Name, 4XXX" if (match.Success) { var su = match.Groups[1].Value; var pc = Convert.ToInt32(match.Groups[2].Value); suburb = REIQ.Access.Suburb.Get(su, pc); //save search query into DB for stats if (suburb != null && !String.IsNullOrEmpty(suburb.name)) { Suburb.LogSuburbSearch(suburb); } } else if (Regex.IsMatch(keyword, "^4[0-9]{3}$")) // postcode only { postcode = Convert.ToInt32(keyword); } else if (Regex.IsMatch(keyword, "^\\d+$")) // is purely numeric, so check if this is a property id { Int32 potentialPropertyID = 0; if (Int32.TryParse(keyword, out potentialPropertyID))//To avoid throwing of errors if the number is very big like "12234456677" { //get any property using (var conn = Data.CreateConnection()) { property = conn.Query <Entities.Property>("SELECT * FROM tblProperty WITH (NOLOCK) WHERE pId = @pID", new { pID = potentialPropertyID }).FirstOrDefault(); } if (property == null) { keyword = String.Empty; } //checking if property is hidden for some reason and make redirection in that case if (property != null) { REIQ.Helpers.PropertyHelper.CheckIfHidden(property); } } } else // check to see if this is the name of a suburb or region { var matchingItems = REIQ.Access.Suburb.ListMatching(keyword); if (matchingItems != null && matchingItems.Regions != null && matchingItems.Regions.Count() > 0) { region = matchingItems.Regions[0]; } else if (matchingItems != null && matchingItems.Suburbs != null && matchingItems.Suburbs.Count() > 0) { if (matchingItems.Suburbs.Count() == 1) { suburb = matchingItems.Suburbs[0]; Suburb.LogSuburbSearch(suburb); } else { foreach (var sb in matchingItems.Suburbs) { suburbsList.Add(sb); Suburb.LogSuburbSearch(sb); } } } } } if (property != null) // exact property match { return(Enumerable.Repeat <int>(property.pID, 1)); } if (regionsList.Count == 0 && suburbsList.Count == 0 && suburb == null && !postcode.HasValue && String.IsNullOrEmpty(region) && property == null && !String.IsNullOrEmpty(keyword)) // found nothing! { //if (HttpContext.Current != null) // HttpContext.Current.Response.Redirect("~/?nomatches=1"); //return Enumerable.Empty<int>(); //Street Search IEnumerable <int> streetSearchList = TryStreetSearch(searchType, propertyTypes, excludeUnderOffer, includeSurroundingSuburbs, onlyIfOpenHome, keyword.Replace(",", " "), minPrice, maxPrice, numBedrooms, numBathrooms, sortOption); if (streetSearchList.Count() > 0) { return(streetSearchList); } } var query = new System.Text.StringBuilder(@"SELECT TOP 5000 p.pId FROM tblProperty p LEFT JOIN tblSuburb s ON s.name = p.Suburb AND s.postcode = p.postcode WHERE p.isWebDisplay = 1 AND p.goLive = 0 AND p.hideAHC = 0 AND p.status IN @Status "); query.AppendLine(); // agencyId if (acId > 0) { query.AppendLine("AND p.acId = @AgencyId"); } //get exact suburbs to search List <int> suburbIds = new List <int>(); if (regionsList != null && regionsList.Count > 0) { foreach (var rg in regionsList) { suburbIds = suburbIds.Concat(Access.Suburb.ListIdsOfSuburbsByRegion(rg)).ToList(); //ugly hack for SQL server not accepting more than 200 parameters if (suburbIds.Count > 200) { break; } } } else if (!String.IsNullOrEmpty(region)) { suburbIds = Access.Suburb.ListIdsOfSuburbsByRegion(region); } else if (suburbsList != null && suburbsList.Count > 0) { foreach (var sb in suburbsList) { if (includeSurroundingSuburbs) { if (suburbIds.Count == 0) { suburbIds = Access.Suburb.ListIdsOfSurroundingSuburbs(sb.name, sb.postcode.Value).ToList(); } else { List <int> tempSbs = Access.Suburb.ListIdsOfSurroundingSuburbs(sb.name, sb.postcode.Value).ToList(); suburbIds = suburbIds.Concat(tempSbs).ToList(); } } else { suburbIds.Add(sb.sID); } } } else if (suburb != null) { if (includeSurroundingSuburbs) { suburbIds = Access.Suburb.ListIdsOfSurroundingSuburbs(suburb.name, suburb.postcode.Value).ToList(); } else { suburbIds = new List <int> { suburb.sID }; } } else if (postcode.HasValue) { suburbIds = Access.Suburb.ListIdsOfSuburbsByPostCode(postcode.Value); } // set property type filter switch (searchType) { case Enum.SearchType.bu: query.AppendLine("AND p.type = 'business'"); break; case Enum.SearchType.co: case Enum.SearchType.cr: query.AppendLine("AND p.type = 'commercial'"); break; case Enum.SearchType.ru: query.AppendLine("AND p.type = 'Acreage/Rural'"); break; case Enum.SearchType.ra: case Enum.SearchType.sa: default: query.AppendLine("AND p.type NOT IN ('commercial', 'business')"); if (propertyTypes.Count() > 0) { query.AppendLine("AND p.type IN @PropertyTypes"); } break; } // set status filter var status = new List <string>(); switch (searchType) { case Enum.SearchType.bu: status.Add("For Sale"); status.Add("For Rent"); break; case Enum.SearchType.cr: case Enum.SearchType.ra: status.Add("For Rent"); break; case Enum.SearchType.sa: case Enum.SearchType.ru: case Enum.SearchType.co: default: status.Add("For Sale"); break; } if (!excludeUnderOffer && !status.Contains("For Rent")) { status.Add("Under offer"); } if (onlyIfOpenHome) { query.AppendLine("AND COALESCE(p.homeopen1From, p.homeopen2From) IS NOT NULL"); } if (numBedrooms > 0) { query.AppendLine("AND COALESCE(p.numBedrooms, 0) >= @NumBedrooms"); } if (numBathrooms > 0) { query.AppendLine("AND COALESCE(p.numBathrooms, 0) >= @NumBathrooms"); } // price filter if (minPrice > 0) { query.AppendLine("AND COALESCE(p.commercialPriceYearly, ISNULL(p.priceLow, 0)) >= @MinPrice"); } if (maxPrice > 0) { query.AppendLine("AND COALESCE(p.commercialPriceYearly, p.priceHigh, ISNULL(p.priceLow, 0)) <= @MaxPrice"); } if (suburbIds.Count() > 0) { query.AppendLine("AND s.SID IN @SuburbIds"); } //sort on the most appropriate price field for the property type switch (sortOption) { default: case Enum.SortOptions.Most_recent: query.AppendLine("ORDER BY p.datelisted DESC"); break; case Enum.SortOptions.By_suburb: query.AppendLine("ORDER BY p.suburb, COALESCE(p.commercialPriceYearly, p.priceLow) DESC, p.datelisted DESC"); break; case Enum.SortOptions.Highest_price: query.AppendLine("ORDER BY COALESCE(p.commercialPriceYearly, p.priceLow) DESC, p.datelisted DESC"); break; case Enum.SortOptions.Lowest_price: query.AppendLine("ORDER BY COALESCE(p.commercialPriceYearly, p.priceLow) ASC, p.datelisted DESC"); break; case Enum.SortOptions.Number_bedrooms: query.AppendLine("ORDER BY p.numBedrooms ASC, p.datelisted DESC"); break; } REIQ.Access.Data.TraceWrite("Search query", query.ToString()); //foreach (int id in suburbIds) //{ // REIQ.Access.Data.TraceWrite("SuburbIDS", id.ToString()); //} //REIQ.Access.Data.TraceWrite("Region", region); REIQ.Access.Data.TraceWrite("Property types", string.Join(", ", propertyTypes.ToArray())); REIQ.Access.Data.TraceWrite("Status", string.Join(", ", status.ToArray())); using (var conn = Data.CreateConnection()) { return(from p in conn.Query <Entities.Property>(query.ToString(), new { AgencyId = acId, MinPrice = minPrice, MaxPrice = maxPrice, NumBedrooms = numBedrooms, NumBathrooms = numBathrooms, PropertyTypes = propertyTypes, Status = status, SuburbIds = suburbIds }) select p.pID); } }