public IActionResult Create(Make make) { if (ModelState.IsValid) { _dataContext.Add(make); _dataContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(make)); }
public IActionResult CreatePost() { if (!ModelState.IsValid) { return(View(ModelVM)); } _dataContext.Models.Add(ModelVM.Model); _dataContext.SaveChanges(); return(RedirectToAction("Index")); }
private void PrepareData() { using (var model = new ShopDataContext()) { var category = new Category { Name = "tools" }; var otherCategory = new Category { Name = "food" }; category.Products.Add(new Product() { Name = "Notepad", Category = category, Price = 10.0 }); category.Products.Add(new Product() { Name = "Pencil", Category = category, Price = 4.0 }); category.Products.Add(new Product() { Name = "Pen", Category = category, Price = 6.0 }); otherCategory.Products.Add(new Product() { Name = "Pear", Category = otherCategory, Price = 2.0 }); model.Categories.Add(category); model.Categories.Add(otherCategory); model.SaveChanges(); } }
public IActionResult EditPost() { if (!ModelState.IsValid) { CarVM.Makes = _dataContext.Makes.ToList(); CarVM.Models = _dataContext.Models.ToList(); return(View(CarVM)); } _dataContext.Cars.Update(CarVM.Car); _dataContext.SaveChanges(); UploadImage(); _dataContext.SaveChanges(); return(RedirectToAction("Index")); }
public void Commit() { _dataContext.SaveChanges(); }