예제 #1
0
    private SearchPropertyViewModel ResolveParent()
    {
        if (!_IsParentLoaded)
        {
            _IsParentLoaded = true;

            var li = Name.LastIndexOf('.');
            if (li >= 0)
            {
                var pn = Name.Substring(0, li);

                _Parent = Page.Properties.FirstOrDefault(e => e.Name == pn);

                StringBuilder sb = null;
                for (var p = _Parent; p != null; p = p.Parent)
                {
                    if (sb == null)
                    {
                        sb = new StringBuilder(p.DisplayName);
                    }
                    else
                    {
                        sb.Insert(0, "/").Insert(0, p.DisplayName);
                    }
                }
                _AncestorPath = sb?.ToString();
            }
        }
        return(this);
    }
        public ActionResult Search(SearchPropertyViewModel viewModel, int page = 1)
        {
            if (page <= 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Parameter 'page' must be positive."));
            }

            int productsPerPage = (int)viewModel.ItemsPerPage;


            var filters = _context.Properties
                          .Include(a => a.Bookings)
                          .Where(a => String.IsNullOrEmpty(viewModel.SearchText) || a.City.ToLower().Contains(viewModel.SearchText.ToLower()) || a.Country.Contains(viewModel.SearchText.ToLower()))
                          .Where(a => viewModel.Guests == 0 || a.Guests >= viewModel.Guests)
                          .Where(a => viewModel.Category == Category.All || viewModel.Category == a.Category)
                          .Where(a => !a.Bookings.Any() || a.Bookings.All(b => !(
                                                                              (DateTime.Compare(viewModel.CheckIn, b.StartDate) >= 0 && DateTime.Compare(viewModel.CheckOut, b.EndDate) <= 0) ||
                                                                              (DateTime.Compare(viewModel.CheckIn, b.StartDate) < 0 && DateTime.Compare(viewModel.CheckOut, b.EndDate) > 0) ||
                                                                              (DateTime.Compare(viewModel.CheckIn, b.StartDate) >= 0 && DateTime.Compare(viewModel.CheckIn, b.EndDate) < 0) ||
                                                                              (DateTime.Compare(viewModel.CheckOut, b.StartDate) > 0 && DateTime.Compare(viewModel.CheckOut, b.EndDate) <= 0)
                                                                              )));



            int totalPages = (int)Math.Ceiling(filters.Count() / (double)productsPerPage);

            var filteredProperties = filters.OrderBy(a => a.Id)
                                     .Skip((page - 1) * productsPerPage)
                                     .Take(productsPerPage)
                                     .ToList();

            viewModel = new SearchPropertyViewModel()
            {
                Properties   = filteredProperties,
                SearchText   = viewModel.SearchText,
                CurrentPage  = page,
                TotalPages   = totalPages,
                ItemsPerPage = viewModel.ItemsPerPage,
                Category     = viewModel.Category,
                CheckIn      = viewModel.CheckIn,
                Guests       = viewModel.Guests,
                CheckOut     = viewModel.CheckOut
            };

            return(View("SearchProperty", viewModel));
        }
예제 #3
0
 protected ConditionViewModel(SearchPropertyViewModel property)
 {
     Property = property;
 }
예제 #4
0
 public DateTimeConditionViewModel(SearchPropertyViewModel property)
     : base(property)
 {
     _Operator = Operators.FirstOrDefault(e => e.Token == property.Model.DefaultOperator)?.Token ?? DateOperator.Token;
 }
예제 #5
0
 public StringConditionViewModel(SearchPropertyViewModel property)
     : base(property)
 {
     _Operator = GetDefaultOperator();
 }
예제 #6
0
 public MultipleOptionConditionViewModel(SearchPropertyViewModel property)
     : base(property)
 {
 }
예제 #7
0
 public BooleanConditionViewModel(SearchPropertyViewModel property)
     : base(property)
 {
 }
예제 #8
0
 protected OptionsConditionViewModel(SearchPropertyViewModel property)
     : base(property)
 {
 }
예제 #9
0

        
예제 #10
0
 public EnumConditionViewModel(SearchPropertyViewModel property)
     : base(property)
 {
 }
예제 #11
0
        public IActionResult Search(SearchPropertyViewModel input)
        {
            try
            {
                var query = (IQueryable <Properties>)_examContext.Properties;

                if (input.uniq_Id != null && input.uniq_Id != String.Empty)
                {
                    query = query.Where(d => d.UniqId == input.uniq_Id);
                }

                if (input.property_type != null && input.property_type != String.Empty)
                {
                    query = query.Where(d => d.PropertyType == input.property_type);
                }

                if (input.City != null && input.City != String.Empty)
                {
                    query = query.Where(d => d.City == input.City);
                }

                if (input.amenities != null && input.amenities.Count > 0)
                {
                    foreach (var amenitie in input.amenities)
                    {
                        query = query.Where(d => d.Amenities.Contains(amenitie));
                    }
                }

                var datas = query
                            .ToList()
                            .Select(f => new PropertyResult()
                {
                    AdditionalInfo  = f.AdditionalInfo,
                    Amenities       = f.Amenities,
                    CheckInDate     = f.CheckInDate,
                    CheckOutDate    = f.CheckOutDate,
                    City            = f.City,
                    Country         = f.Country,
                    CrawlDate       = f.CrawlDate,
                    Description     = f.Description,
                    HighlightValue  = f.HighlightValue,
                    HotelStarRating = f.HotelStarRating,
                    ImageCount      = f.ImageCount,
                    ImageUrls       = f.ImageUrls,
                    Internet        = f.Internet,
                    Landmark        = f.Landmark,
                    Latitude        = f.Latitude,
                    Longitude       = f.Longitude,
                    Occupancy       = f.Occupancy,
                    Pageurl         = f.Pageurl,
                    PropertyAddress = f.PropertyAddress,
                    PropertyId      = f.PropertyId,
                    PropertyName    = f.PropertyName,
                    PropertyType    = f.PropertyType,
                    Qts             = f.Qts,
                    QueryTimeStamp  = f.QueryTimeStamp,
                    RoomPrice       = f.RoomPrice,
                    RoomTypes       = f.RoomTypes,
                    SearchTerm      = f.SearchTerm,
                    ServiceValue    = f.ServiceValue,
                    SimilarHotel    = f.SimilarHotel,
                    Sitename        = f.Sitename,
                    ThingsToDo      = f.ThingsToDo,
                    ThingsToNote    = f.ThingsToNote,
                    UniqId          = f.UniqId,
                    CustomRoomPirce = Convert.ToDouble(f.RoomPrice.Split("per night incl. tax")[0]),
                    Point           = new GeoCoordinate(Convert.ToDouble(f.Latitude), Convert.ToDouble(f.Longitude)),
                    area            = 0
                }).ToList();

                if (input.room_price != null && input.room_price != String.Empty)
                {
                    if (FindTextInSTR(input.room_price, "-"))
                    {
                        string[] splitString = input.room_price.Split("-");
                        double   minPrice    = Convert.ToDouble(splitString[0]);
                        double   maxPrice    = Convert.ToDouble(splitString[1]);
                        datas = datas.Where(o => o.CustomRoomPirce >= minPrice && o.CustomRoomPirce <= maxPrice).ToList();
                    }
                }

                if ((input.Location != null && input.Location != String.Empty) && (input.radius != null))
                {
                    if (FindTextInSTR(input.Location, ","))
                    {
                        string[]      splitString = input.Location.Split(",");
                        double        latitude    = Convert.ToDouble(splitString[0]);
                        double        longitude   = Convert.ToDouble(splitString[1]);
                        GeoCoordinate center      = new GeoCoordinate(latitude, longitude);
                        foreach (var data in datas)
                        {
                            data.area = data.Point.GetDistanceTo(center);
                        }

                        datas = datas.Where(f => f.area <= input.radius).ToList();
                    }
                }

                var model = new ResultItemsViewModel <PropertyResult>(datas.Count, datas);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }