Exemple #1
0
        public IActionResult Map()
        {
            var model = new ObjectsMapViewModel();

            model.Search = new Search()
            {
                ObjectAttributes = _touristObject.GetAllObjectAttributes()
                                   .Select(atr => new ObjectAttributesModel()
                {
                    Id = atr.Id, Name = atr.Name, Selected = false
                }).ToList(),
                ObjectTypes = _touristObject.GetObjectTypes()
                              .Select(type => new ObjectTypeModel()
                {
                    Id = type.Id, Name = type.Name, Selected = false
                }).ToList(),
            };



            model.ObjectsList = _touristObject.GetAllObjects()
                                .Select(ob => new ObjectItemModel()
            {
                Id                 = ob.Id,
                Name               = ob.Name,
                Location           = ob.City != null ? ob.Address + ", " + ob.City.Name : ob.Address,
                ImgSrc             = ob.ObjectImages.Count > 0 ? ob.ObjectImages.ElementAt(0).Path : "/pink.png",
                Lat                = ob.Lat,
                Lng                = ob.Lng,
                Description        = ob.Description,
                WebContact         = ob.WebContact,
                EmailContact       = ob.EmailContact,
                PhoneNumberContact = ob.PhoneNumberContact,
                Type               = ob.ObjectType == null ? "" : ob.ObjectType.Name,
                NumberOfRatings    = _touristObject.GetNumberOfRatings(ob.Id),
                Rating             = Math.Round(_touristObject.GetAvarageRating(ob.Id), 2),
            }).ToList();



            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> FilterObjectsMap(ObjectsMapViewModel model)
        {
            var currency = Request.Cookies["Currency"] == null ? "BAM" : Request.Cookies["Currency"];


            model.ObjectsList = (await _touristObject.GetAllFilteredObjects(model.Search, currency))
                                .Select(ob => new ObjectItemModel()
            {
                Id                 = ob.Id,
                Name               = ob.Name,
                Location           = ob.City != null ? ob.Address + ", " + ob.City.Name : ob.Address,
                ImgSrc             = ob.ObjectImages.Count > 0 ? ob.ObjectImages.ElementAt(0).Path : "/pink.png",
                Lat                = ob.Lat,
                Lng                = ob.Lng,
                Description        = ob.Description,
                WebContact         = ob.WebContact,
                EmailContact       = ob.EmailContact,
                PhoneNumberContact = ob.PhoneNumberContact,
                Type               = ob.ObjectType == null ? "" : ob.ObjectType.Name,
                NumberOfRatings    = _touristObject.GetNumberOfRatings(ob.Id),
                Rating             = Math.Round(_touristObject.GetAvarageRating(ob.Id), 2),
            }).ToList();

            if (!string.IsNullOrWhiteSpace(model.Search.SearchString))
            {
                var coordinates = _touristObject.GetCityCoordinates(model.Search.SearchString);
                if (coordinates == null)
                {
                    coordinates = _touristObject.GetCountryCoordinates(model.Search.SearchString);
                }

                if (coordinates != null)
                {
                    model.CenterLat = coordinates.Lat;
                    model.CenterLng = coordinates.Lng;
                }
            }

            return(PartialView("ObjectsMap", model));
        }