public ActionResult Index(long id, string pageUrl = "")
        {
            var resort = meridian.resortsStore.Get(id);

            if (resort.is_published)
            {
                var model = new EntityViewModel
                {
                    Title = resort.title,
                    FieldSet = resort.GetFieldset(pageUrl),
                    MenuLinks = resort.GetMenuLinks(resort.EntityUri().ToString(), pageUrl),
                    Photos = resort.GetPhotos(),
                    Entity = resort,
                    EntityMap = resort,
                    ListImageUrl = Extensions.Extensions.ToAbsoluteUrl(resort.GetListImage())
                };

                var searchModel = new SearchViewModel
                {
                    ResortId = id,
                    SubTerritoryId = resort.territory_id,
                    RootTerritoryId = resort.GetResortsTerritorie() == null ? 0 : resort.GetResortsTerritorie().parent_id
                };

                long terrId = searchModel.RootTerritoryId;
                long rootId = searchModel.RootTerritoryId;
                long subId = searchModel.SubTerritoryId;

                while (terrId > 0)
                {
                    var terr = meridian.territoriesStore.Get(terrId);
                    if (terr.parent_id > 0)
                    {
                        rootId = terr.parent_id;
                        subId = terr.id;
                    }

                    terrId = terr.parent_id;
                }

                searchModel.RootTerritoryId = rootId;
                searchModel.TerritoryId = subId;

                ViewBag.SearchModel = searchModel;

                LastViewEntities.AddItemToLastViewed(resort.ProtoName, resort.id);

                return View(model);
            }

            throw new HttpException(404, "Отель не найден");
        }
        public ActionResult HotelResults(SearchViewModel model, int page = 1, int pageSize = Constants.PageSize)
        {
            var hotels = meridian.hotelsStore.All().Where(item => item.is_published).AsQueryable();

            if (model.DeseaseId > 0)
            {
                hotels = hotels.Where(item => item.deseases_items.Any(d => d.id == model.DeseaseId));
            }

            if (model.TreatmentId > 0)
            {
                var ids = new List<long> {model.TreatmentId};

                var treatment = meridian.treatment_optionsStore.Get(model.TreatmentId);

                if (treatment.parent_id == 0)
                {
                    ids.AddRange(treatment.SubTreatmentOptions.Select(item => item.id).ToList());
                }

                hotels = hotels.Where(item => item.treatment_options_items.Select(t => t.id).Intersect(ids).Any());
            }

            long territoryId = 0;

            if (model.RootTerritoryId > 0)
            {
                territoryId = model.RootTerritoryId;
            }

            if (model.TerritoryId > 0)
            {
                var territory = meridian.territoriesStore.Get(model.TerritoryId);
                model.RootTerritoryId = territory.parent_id;
                territoryId = model.TerritoryId;
            }

            if (model.SubTerritoryId > 0)
            {
                territoryId = model.SubTerritoryId;
            }

            if (territoryId > 0)
            {
                var territoryIds = GetSubTerritoryIds(territoryId);
                var resortIds = meridian.resortsStore.All()
                        .Where(item => territoryIds.Contains(item.territory_id))
                        .Select(item => item.id);

                hotels = hotels.Where(item => resortIds.Contains(item.resort_id));
            }

            if (!string.IsNullOrEmpty(model.Title))
            {
                hotels = hotels.Where(item => item.title.ToLower().Contains(model.Title.ToLower()));
            }

            if (model.PriceFrom > 0 && model.PriceTo > 0)
            {
                var month = DateTime.Now.Month;
                var prices = meridian.pricesStore.All().Where(item => item.month == month && item.proto_name == "hotels" && item.price >= model.PriceFrom && item.price <= model.PriceTo).Select(item=> item.entity_id);
                if (hotels.Any(item => prices.Contains(item.id)))
                {
                    hotels = hotels.Where(item => prices.Contains(item.id));
                }
            }

            if (model.Stars > 0)
            {
                hotels = hotels.Where(item => item.stars == model.Stars);
            }

            if (model.HotelClass > 0)
            {
                hotels = hotels.Where(item => item.class_id == model.HotelClass);
            }

            if (model.Properties != null && model.Properties.Any())
            {
                foreach (var propertyId in model.Properties)
                {
                    hotels = hotels.Where(item => item.properties_items.Any(p => p.id == propertyId));
                }
            }

            if (model.Treatments != null && model.Treatments.Any())
            {
                var hotelIds = new List<long>();

                foreach (var treatementId in model.Treatments)
                {
                    var ids = meridian.hotelsStore.All()
                            .Where(item => item.treatment_options_items.Any(t => t.id == treatementId))
                            .Select(item => item.id);
                    hotelIds.AddRange(ids);
                }

                hotelIds = hotelIds.Distinct().ToList();
                hotels = hotels.Where(item => hotelIds.Contains(item.id));
            }

            ViewBag.Results = EntityMapper.ToHotelsListViewModel(hotels.ToList(), page, pageSize);

            return View(model);
        }
 public ActionResult CureProfiles(SearchViewModel model)
 {
     return View(model);
 }
        public ActionResult ResortSearch(SearchViewModel model)
        {
            if (model.DeseaseId > 0)
            {
                var desease = meridian.deseasesStore.Get(model.DeseaseId);

                if (desease.CureProfile != null)
                {
                    model.CureProfileId = desease.CureProfile.id;
                }
            }

            if (model.AdditionalDeseaseId > 0)
            {
                var desease = meridian.deseasesStore.Get(model.AdditionalDeseaseId);

                if (desease.CureProfile != null)
                {
                    model.AdditionalCureProfileId = desease.CureProfile.id;
                }
            }

            if (model.TerritoryId > 0)
            {
                var territory = meridian.territoriesStore.Get(model.TerritoryId);
                model.RootTerritoryId = territory.parent_id;
            }

            return View(model);
        }
        public ActionResult ResortResults(SearchViewModel model, int page = 1, int pageSize = Constants.PageSize)
        {
            var resorts = meridian.resortsStore.All().Where(item => item.is_published).AsQueryable();

            if (model.HealthFactorId > 0)
            {
                resorts = resorts.Where(item => item.health_factors_items.Any(h => h.id == model.HealthFactorId));
            }

            if (model.DeseaseId > 0)
            {
                var hotelIds = meridian.hotelsStore.All()
                        .Where(item => item.deseases_items.Any(d => d.id == model.DeseaseId))
                        .Select(item => item.id);

                resorts = resorts.Where(item => item.Hotels.Any(h => hotelIds.Contains(h.id)));
            }

            if (model.DeseaseId == 0 && model.CureProfileId > 0)
            {
                resorts = resorts.Where(item => item.cure_profiles_items.Any(c => c.id == model.CureProfileId));
            }

            if (model.AdditionalCureProfileId > 0)
            {
                resorts = resorts.Where(item => item.cure_profiles_items.Any(c => c.id == model.AdditionalCureProfileId));
            }

            long territoryId = 0;

            if (model.RootTerritoryId > 0)
            {
                territoryId = model.RootTerritoryId;
            }

            if (model.TerritoryId > 0)
            {
                var territory = meridian.territoriesStore.Get(model.TerritoryId);
                model.RootTerritoryId = territory.parent_id;
                territoryId = model.TerritoryId;
            }

            if (model.SubTerritoryId > 0)
            {
                territoryId = model.SubTerritoryId;
            }

            if (territoryId > 0)
            {
                var territoryIds = GetSubTerritoryIds(territoryId);
                resorts = resorts.Where(item => territoryIds.Contains(item.territory_id));
            }

            if (!string.IsNullOrEmpty(model.Title))
            {
                resorts = resorts.Where(item => item.title.ToLower().Contains(model.Title.ToLower()));
            }

            var results = EntityMapper.ToResortsListViewModel(resorts.ToList(), page, pageSize);
            ViewBag.Results = results;

            if (results.TotalCount == 0 && model.CureProfileId > 0)
            {
                var suggestedResorts = meridian.resortsStore.All().Where(item => item.cure_profiles_items.Any(c => c.id == model.CureProfileId)).Take(8);
                ViewBag.SuggestedResults = EntityMapper.ToResortsListViewModel(suggestedResorts.ToList(), 1, 8);
            }
            else
            {
                ViewBag.SuggestedResults = null;
            }

            return View(model);
        }
        public ActionResult HotelSearch(SearchViewModel model)
        {
            var month = DateTime.Now.Month;
            var prices = meridian.pricesStore.All().Where(item => item.month == month && item.proto_name == "hotels").ToList();

            if (prices.Any())
            {
                model.MinPrice = Convert.ToInt32(prices.Min(item => item.price));
                model.MaxPrice = Convert.ToInt32(prices.Max(item => item.price));
            }

            model.HotelClasses =
                meridian.hotel_classesStore.All()
                    .Select(item => new SelectListItem {Text = item.title, Value = item.id.ToString()})
                    .ToList();

            model.HotelClasses.Insert(0, new SelectListItem{Text = "Любой", Value = "0", Selected = true});

            model.HotelStars =
                Enumerable.Range(1, 5).Reverse()
                    .Select(item => new SelectListItem {Text = item.ToString(), Value = item.ToString()})
                    .ToList();

            model.HotelStars.Insert(0, new SelectListItem { Text = "Все", Value = "0", Selected = true });

            model.TreatmentOptions = meridian.treatment_optionsStore.All().Where(item => item.parent_id == 0 && item.SubTreatmentOptions.Any()).ToList();

            model.Categories = meridian.property_categoriesStore.All().Where(item => item.show_in_search).OrderBy(item => item.order_number).ToList();

            return View(model);
        }