示例#1
0
        public IActionResult Create(Make make)
        {
            if (ModelState.IsValid)
            {
                _dataContext.Add(make);
                _dataContext.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(make));
        }
示例#2
0
        public IActionResult CreatePost()
        {
            if (!ModelState.IsValid)
            {
                return(View(ModelVM));
            }

            _dataContext.Models.Add(ModelVM.Model);
            _dataContext.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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"));
        }
示例#5
0
 public void Commit()
 {
     _dataContext.SaveChanges();
 }