예제 #1
0
        public JsonResult GetRestaurantsAndDishes(SearchModel model)
        {
            //sätter denna här så länge
            model.Week = CalendarManager.GetCurrentWeek();
            model.Year = DateTime.Now.Year;
            model.Day = (int)DateTime.Now.DayOfWeek;

            // todo remove test
            model.Day = 3;

            if (string.IsNullOrEmpty(model.SearchString)) model.SearchString = "";
            model = service.GetResturantsAndDishes(model);
            model.Partial = RenderPartialViewToString("RestaurantsPartial", model.Restaurants);

            var addsList = new List<AddsColumnRowModel>();
            var adds = service.GetAddsByLunchArea(model.AreaId).ToList();
            for (int i = 0; i < adds.Count; i++)
            {
                var item = new AddsColumnRowModel { First = adds[i], Second = adds[i+1] };
                addsList.Add(item);
                i++;
            }

            model.PartialAdds = RenderPartialViewToString("AddsColumnPartial", addsList);
            return Json(model);
        }
예제 #2
0
 /// <summary>
 /// hämta alla restauranger och rätter
 /// </summary>
 public SearchModel GetResturantsAndDishes(SearchModel model)
 {
     model.AreaDescription = GetLunchAreaById(model.AreaId).Description;
     //model.Restaurants = CreateRestaurantsViewModels(RestaurantManager.GetRestaurants(model)).ToList();
     //model.Restaurants = RestaurantManager.GetRestaurants(model).Select(r => CreateRestaurantMenusViewModel(r, model)).ToList();
     model.Restaurants = RestaurantManager.GetRestaurantsWithMenus(model).Select(r => CreateRestaurantMenusViewModel(r, model)).ToList();
     model.SearchCount = model.Restaurants.Count;
     return model;
 }
예제 #3
0
        public static List<Restaurant> GetRestaurants(SearchModel model)
        {
            var result = GetRestaurants().Where(l => l.Areas.Any(x => x.Id == model.AreaId)).ToList();

            if (string.IsNullOrEmpty(model.SearchString))
                return result.ToList();

            var str = model.SearchString.ToLower();
            var filteredList = result.Where(r =>
                r.Name.ToLower().Contains(str) || r.Information.ToLower().Contains(str)
                || (r.Dishes.Any(d => d.ShortName.ToLower().Contains(str)) ||
                r.Dishes.Any(d => d.Description.ToLower().Contains(str)))
                );

            return filteredList.Any() ? filteredList.ToList() : null;
        }
예제 #4
0
        public ActionResult Search(SearchModel searchModel)
        {
            Point location;
            if (string.IsNullOrWhiteSpace(searchModel.Location))
            {
                location = GetUserLocation();
            }
            else
            {
                location = _geoCodingService.GetCoordinates(searchModel.Location);
                if (location == null)
                {
                    TempData[ViewDataKeys.Message] = new FailMessage(string.Format(Resources.GeoCodeFail, searchModel.Location));
                }
            }

            if (location != null)
            {
                var services = ExecuteQuery(new AdvancedSearch(searchModel, location, Distance));

                LogImpressions(services);

                ViewData[ViewDataKeys.Services] = services;
                ViewData[ViewDataKeys.ServiceSerializationInfos] = Mapper.Map<IEnumerable<ServiceSerializeInfo>>(services);
                ViewData[ViewDataKeys.UserLocation] = location;
            }

            ViewData[ViewDataKeys.Categories] = GetCategories();
            ViewData[ViewDataKeys.ServiceTypes] = GetServiceTypes();
            ViewData[ViewDataKeys.SortTypes] = GetSortTypes();

            return View(searchModel);
        }
예제 #5
0
 public RestaurantModel GetRestaurantWithMenu(long restaurangId, SearchModel model)
 {
     var r = CreateRestaurantMenusViewModel(RestaurantManager.GetRestaurant(restaurangId), model);
     return r;
 }
예제 #6
0
        private static RestaurantModel CreateRestaurantMenusViewModel(Restaurant r, SearchModel model)
        {
            var days = r.Menus.FirstOrDefault(m => m.Week == model.Week && m.Year == model.Year).Days;
            //var day = days.FirstOrDefault(x => (int) x.DayOfWeek == model.Day);
            //var dddd =
            var dishes = days.SelectMany( x => x.Dishes.Select(d => new MenuDishViewModel
                                        {
                                            Day = d.MenuDay.DayOfWeekId,
                                            Id = d.Dish.Id,
                                            ShortName = d.Dish.ShortName,
                                            Description = d.Dish.Description,
                                            DishType = d.Dish.DishType.ToString(),
                                            KitchenType = d.Dish.KitchenType.ToString()
                                        }));

            var rest = new RestaurantMenuViewModel
            {
                Id = r.Id,
                Name = r.Name,
                Description = r.Description,
                Information = r.Information,
                Email = r.Email,
                //LunchAreas = r
                Adress =
                    new AdressViewModel
                    {
                        PostArea = r.Adress.PostArea,
                        Street = r.Adress.Street,
                        PostCode = r.Adress.PostCode
                    },
                Url = r.Url,
                Phone = r.PhoneNumbers.Any() ? r.PhoneNumbers.FirstOrDefault().Number : "", //   r.PhoneNumbers.FirstOrDefault().Number,
                //  Contact = new UserViewModel(), // new UserViewModel { Email = r.Contacts.FirstOrDefault().Email, Id = r.Contacts.FirstOrDefault().Id, FirstName = r.Contacts.FirstOrDefault().FirstName, LastName = r.Contacts.FirstOrDefault().LastName, Phone = r.Contacts.FirstOrDefault().PhoneNumbers.FirstOrDefault().Number },
                Dishes = dishes
            };
            return rest;
        }
        public void Search_With_Location()
        {
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);
            var services = GetSampleServices();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<IQuery<IEnumerable<Service>>>()))
                .Returns(services);

            var categories = GetSampleCategories();
            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>()))
                .Returns(categories);

            var fileSystemMock = new Mock<IFileSystem>();
            var geoCodingServicemMock = new Mock<IGeoCodingService>();
            const string location = "Bar";
            var locationCood = PointFactory.Create(6.9419444, 79.8977778);
            geoCodingServicemMock.Setup(g => g.GetCoordinates(It.Is<string>(v => v == location)))
                .Returns(locationCood);

            var userLocation = PointFactory.Create(6.9319444, 79.8877778);
            var controller = new ServicesController(nHbernateContextMock.Object, fileSystemMock.Object, geoCodingServicemMock.Object);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Services/Search", UserName));
            controller.SetUserInfoWitLocation(userLocation);

            var model = new SearchModel { Terms = "Foo", Location = location };
            controller.Search(model);

            Assert.AreEqual(model, controller.ViewData.Model);
            Assert.AreEqual(locationCood, controller.ViewData[ViewDataKeys.UserLocation]);
        }