private List<EateryModel> GetPossibleEateryList(bool isWalkingDistance, FoodStyleModel style)
        {
            var eateries = db.EateryModels.Where(x => x.IsWalkingDistance == isWalkingDistance);
            if (style.Id != 0)
                eateries = eateries.Where(x => x.FoodStyleModel.Id == style.Id);

            return eateries.OrderBy(c => c.Name).ToList();
        }
 public ActionResult Edit(FoodStyleModel foodstylemodel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(foodstylemodel).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(foodstylemodel);
 }
        public ActionResult Create(FoodStyleModel foodstylemodel)
        {
            if (ModelState.IsValid)
            {
                db.FoodStyleModels.Add(foodstylemodel);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(foodstylemodel);
        }
        private void setFormValues(FormCollection values, SearchViewModel viewModel)
        {
            var isWalkingDistance = GetIsWalkingDistanceFromForm(values);
            var style = GetStyleFromForm(values);
            //if style is null that means they dont care what they want
            if (style == null)
                style = new FoodStyleModel() { Id = 0 };

            viewModel.IsWalkingDistance = isWalkingDistance;
            viewModel.Eateries =
                GetPossibleEateryList(isWalkingDistance, style);
            viewModel.SuggestedEatery = GetSuggestionFromList(viewModel.Eateries);
            viewModel.Styles = GetStyleListOptions(style);
        }
 private IEnumerable<SelectListItem> GetStyleListOptions(FoodStyleModel style)
 {
     var styles = db.FoodStyleModels.ToList();
     styles.Add(new FoodStyleModel(){Id=0, Name = "(anything)"});
     return styles.OrderBy(x => x.Name).Select(c => new SelectListItem() { Value = c.Id.ToString(), Text = c.Name, Selected = style.Id == c.Id });
 }
 private EateryViewModel CreateViewModelFromEntityModel(EateryModel eaterymodel, FoodStyleModel selected)
 {
     var viewModel = new EateryViewModel()
                         {
                             Eatery = eaterymodel,
                             Styles = new SelectList(db.FoodStyleModels.OrderBy(x => x.Name), "Id", "Name", selected)
                         };
     return viewModel;
 }