コード例 #1
0
        public ActionResult Create([Bind(Include = "id,title,author,format,price")] book book)
        {
            if (ModelState.IsValid)
            {
                db.books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,Brand")] Car car)
        {
            if (ModelState.IsValid)
            {
                db.CarSet.Add(car);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(car));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "StudentID,Name,City,Mobile,Email,State")] Student student)
        {
            if (ModelState.IsValid)
            {
                student.StudentID = Guid.NewGuid();
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,CarId")] Model model)
        {
            if (ModelState.IsValid)
            {
                db.ModelSet.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CarId = new SelectList(db.CarSet, "Id", "Brand", model.CarId);
            return(View(model));
        }
コード例 #5
0
ファイル: EmpDAL.cs プロジェクト: wakemeupoct/MVC-Demo
 public void AddNewEmpployee(Employee employee)
 {
     try
     {
         using (entities)
         {
             entities.Employee.Add(employee);
             entities.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #6
0
 public void Update(product product)
 {
     using (var db = new MVCDemoEntities())
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
コード例 #7
0
        public void Add(product product)
        {
            product.created_date = DateTime.Now;
            product.created_by   = "web";

            using (var db = new MVCDemoEntities())
            {
                db.products.Add(product);
                db.SaveChanges();
            }
        }
コード例 #8
0
        public void Delete(int id)
        {
            using (var db = new MVCDemoEntities())
            {
                var product = db.products.Where(s => s.id == id).FirstOrDefault();
                if (product != null)
                {
                    db.products.Remove(product);
                    db.SaveChanges();
                }
            }

            //using (var db = new MVCDemoEntities())
            //{
            //    db.USP_PRODUCTS_DELETE(id);
            //}
        }