public ActionResult Create(EateryViewModel eaterymodel) { var eatery = eaterymodel.Eatery; eatery.FoodStyleModel = db.FoodStyleModels.FirstOrDefault(x => x.Id == eatery.FoodStyleModel.Id); db.EateryModels.Add(eatery); db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult Edit(EateryViewModel eaterymodel) { var eatery = eaterymodel.Eatery; var fromDB = db.EateryModels.Where(x => x.Id == eatery.Id).FirstOrDefault(); fromDB.Name = eatery.Name; fromDB.IsWalkingDistance = eatery.IsWalkingDistance; fromDB.FoodStyleModel = db.FoodStyleModels.Where(x=>x.Id == eatery.FoodStyleModel.Id).FirstOrDefault(); db.Entry(fromDB).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); }
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; }