public ActionResult Create([Bind(Include = "instructorID,firstName,lastName,subject,salary")] Instructor instructor)
        {
            if (ModelState.IsValid)
            {
                db.Instructors.Add(instructor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(instructor));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "studentID,firstName,lastName,email,studentSince")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "courseID,description,courseStarted,studentID")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.studentID = new SelectList(db.Students, "studentID", "firstName", course.studentID);
            return(View(course));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "coursedetailID,price,courseID,instructorID")] CourseDetail courseDetail)
        {
            if (ModelState.IsValid)
            {
                db.CourseDetails.Add(courseDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.courseID     = new SelectList(db.Courses, "courseID", "description", courseDetail.courseID);
            ViewBag.instructorID = new SelectList(db.Instructors, "instructorID", "firstName", courseDetail.instructorID);
            return(View(courseDetail));
        }
Exemplo n.º 5
0
        public void CanSoftDelete()
        {
            //Arrange
            int id;

            using (var db = new Context2())
            {
                var p = new Product();

                db.Products.Add(p);

                var q = new Quote
                {
                    Name         = "CanSoftDelete",
                    QuoteDetails = new[]
                    {
                        new QuoteDetail {
                            Name = "Item 1", Product = p
                        },
                        new QuoteDetail {
                            Name = "Item 2", Product = p
                        }
                    }
                };

                db.Quotes.Add(q);
                db.SaveChanges();
                id = q.Id;
            }

            //Act
            using (var db = new Context2())
            {
                var q = db.Quotes.Single(x => x.Id == id);
                db.Quotes.Remove(q);
                db.SaveChanges();
            }

            //Assert
            using (var db = new Context2())
            {
                Assert.That(db.Quotes.Any(x => x.Id == id), Is.False);
            }
        }