public ActionResult Create(ViewModels.BilCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new Models.BilModel2()) { var bil = new Models.Bil { Color = model.Color, Manufacturer = model.Manufacturer, Model = model.Modell, Year = model.Year }; db.Bilar.Add(bil); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(ViewModels.BilCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var db = new Models.DBContext(); var newId = db.GetAll().Max(r => r.Id) + 1; var bil = new Models.Bil { Id = newId, Color = model.Color, Manufacturer = model.Manufacturer, Model = model.Modell, Year = model.Year }; db.AddBil(bil); return(RedirectToAction("Index")); }
public ActionResult Create() { var model = new ViewModels.BilCreateViewModel(); return(View(model)); }