public ActionResult Index() { var categories = this.Cache.Get("categories", () => this.categories.GetAll().To <CategoryViewModel>().ToList(), GlobalConstants.CategoriesCacheTimeInSeconds); var model = new RestaurantFilterResponseViewModel { Distance = 1, Categories = DropDownListGenerator.GetCategorySelectListItems(categories) }; return(this.View(model)); }
public ActionResult Change(ChangeCategoryViewModel model) { if (!this.ModelState.IsValid) { var categories = this.Cache.Get("categories", () => this.categories.GetAll().To <CategoryViewModel>().ToList(), GlobalConstants.CategoriesCacheTimeInSeconds); model.Categories = DropDownListGenerator.GetCategorySelectListItems(categories); this.TempData["SuccessNotification"] = "Restaurant category not changed"; return(this.View(model)); } var restaurantId = this.User.Identity.GetUserId(); var categoryId = model.CategoryId; this.restaurants.UpdateCategory(categoryId, restaurantId); this.TempData["SuccessNotification"] = "Successfuly changed the restaurant category"; return(this.RedirectToAction("Details", "Restaurant", new { area = string.Empty, id = restaurantId })); }
public ActionResult Change() { var categories = this.Cache.Get("categories", () => this.categories.GetAll().To <CategoryViewModel>().ToList(), GlobalConstants.CategoriesCacheTimeInSeconds); var restaurantId = this.User.Identity.GetUserId(); var currentCategoryId = this.restaurants.GetCurrentCategoryId(restaurantId); if (currentCategoryId == null) { currentCategoryId = categories.Where(x => x.Name == "All").FirstOrDefault().Id; this.restaurants.UpdateCategory((int)currentCategoryId, restaurantId); } var model = new ChangeCategoryViewModel() { CategoryId = (int)currentCategoryId, Categories = DropDownListGenerator.GetCategorySelectListItems(categories) }; return(this.View(model)); }