public async Task <ActionResult> Create([Bind(Include = "ID,EnrollmentDate,LastName,FirstMidName")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Students.Add(student);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(student));
        }
        public async Task <ActionResult> Create([Bind(Include = "CourseID,Title,Credits")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(course));
        }
        public async Task <ActionResult> Create([Bind(Include = "InstructorID,Location")] OfficeAssignment officeAssignment)
        {
            if (ModelState.IsValid)
            {
                db.OfficeAssignments.Add(officeAssignment);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.InstructorID = new SelectList(db.Instructors, "ID", "LastName", officeAssignment.InstructorID);
            return(View(officeAssignment));
        }
Beispiel #4
0
        public async Task <ActionResult> Create([Bind(Include = "ID,HireDate,LastName,FirstMidName")] Instructor instructor)
        {
            if (ModelState.IsValid)
            {
                db.Instructors.Add(instructor);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.ID = new SelectList(db.OfficeAssignments, "InstructorID", "Location", instructor.ID);
            return(View(instructor));
        }
        public async Task <ActionResult> Create([Bind(Include = "EnrollmentID,CourseID,StudentID,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                db.Enrollments.Add(enrollment);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CourseID  = new SelectList(db.Courses, "CourseID", "Title", enrollment.CourseID);
            ViewBag.StudentID = new SelectList(db.Students, "ID", "LastName", enrollment.StudentID);
            return(View(enrollment));
        }
Beispiel #6
0
        // DELETE odata/TodoItems(5)
        public async Task <IHttpActionResult> Delete([FromODataUri] int key)
        {
            var items = _context.Set <T>();
            T   item  = await items.FindAsync(key);

            if (item == null)
            {
                return(NotFound());
            }

            items.Remove(item);
            await _context.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }